Skip to content

Commit

Permalink
Use vscode-extension-proposals to unify proposal logic (redhat-develo…
Browse files Browse the repository at this point in the history
…per#3101)

- Use newest extension-proposals 0.0.21
- Fixes redhat-developer#3099 

Signed-off-by: Rob Stryker <[email protected]>
  • Loading branch information
robstryker authored and gayanper committed May 27, 2023
1 parent fd18475 commit 31399dd
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 182 deletions.
159 changes: 81 additions & 78 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1475,6 +1475,7 @@
"@vscode/webview-ui-toolkit": "1.2.2",
"chokidar": "^3.5.3",
"@redhat-developer/vscode-redhat-telemetry": "^0.6.1",
"@redhat-developer/vscode-extension-proposals": "0.0.21",
"expand-home-dir": "^0.0.3",
"fmtr": "^1.1.2",
"fs-extra": "^8.1.0",
Expand Down
5 changes: 3 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { convertToGlob, deleteDirectory, ensureExists, getBuildFilePatterns, get
import glob = require('glob');
import { Telemetry } from './telemetry';
import { getMessage } from './errorUtils';
import { TelemetryService } from '@redhat-developer/vscode-redhat-telemetry/lib';

const syntaxClient: SyntaxLanguageClient = new SyntaxLanguageClient();
const standardClient: StandardLanguageClient = new StandardLanguageClient();
Expand Down Expand Up @@ -101,11 +102,11 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
clientLogFile = path.join(storagePath, 'client.log');
initializeLogFile(clientLogFile);

Telemetry.startTelemetry(context);
const telemetryService: Promise<TelemetryService> = Telemetry.startTelemetry(context);

enableJavadocSymbols();

initializeRecommendation(context);
initializeRecommendation(context, telemetryService);

registerOutOfMemoryDetection(storagePath);

Expand Down
48 changes: 28 additions & 20 deletions src/recommendation/dependencyAnalytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,42 @@

'use strict';

import { IRecommendationService, Recommendation } from "@redhat-developer/vscode-extension-proposals/lib";
import * as vscode from "vscode";
import { IHandler } from "./handler";

const EXTENSION_NAME = "redhat.fabric8-analytics";
const GH_ORG_URL = `https://github.com/fabric8-analytics`;
const RECOMMENDATION_MESSAGE = `Do you want to install the [Dependency Analytics](${GH_ORG_URL}) extension to stay informed about vulnerable dependencies in pom.xml files?`;
const JAVA_DEPENDENCY_ANALYTICS_SHOW = "java.recommendations.dependency.analytics.show";

function isPomDotXml(uri: vscode.Uri) {
return !!uri.path && uri.path.toLowerCase().endsWith("pom.xml");
let alreadyShown = false;
export function initialize (context: vscode.ExtensionContext, recommendService: IRecommendationService): Recommendation[] {
const ret: Recommendation = createDependencyRecommendation(recommendService);
delayedShowDependencyRecommendation(context, recommendService);
return [ret];
}

export function initialize (context: vscode.ExtensionContext, handler: IHandler): void {
const show = vscode.workspace.getConfiguration().get(JAVA_DEPENDENCY_ANALYTICS_SHOW);
if (!show) {
return;
}
if (!handler.canRecommendExtension(EXTENSION_NAME)) {
return;
}
context.subscriptions.push(vscode.workspace.onDidOpenTextDocument(e => {
if (isPomDotXml(e.uri)) {
handler.handle(EXTENSION_NAME, RECOMMENDATION_MESSAGE);
}
}));
function createDependencyRecommendation(recommendService: IRecommendationService): Recommendation {
const r1 = recommendService.create(EXTENSION_NAME, "Dependency Analytics",
`The [Dependency Analytics](${GH_ORG_URL}) extension helps you to stay informed about vulnerable dependencies in pom.xml files.`, false);
return r1;
}

async function delayedShowDependencyRecommendation (context: vscode.ExtensionContext, recommendService: IRecommendationService): Promise<void> {
await new Promise(f => setTimeout(f, 6000));
const isPomDotXmlOpened = vscode.workspace.textDocuments.findIndex(doc => isPomDotXml(doc.uri)) !== -1;
if (isPomDotXmlOpened) {
handler.handle(EXTENSION_NAME, RECOMMENDATION_MESSAGE);
recommendService.show(EXTENSION_NAME);
} else {
context.subscriptions.push(vscode.workspace.onDidOpenTextDocument(e => {
// I would prefer to delete this listener after showing once, but i can't figure out how ;)
if( !alreadyShown ) {
if (isPomDotXml(e.uri)) {
recommendService.show(EXTENSION_NAME);
alreadyShown = true;
}
}
}));
}
}

function isPomDotXml(uri: vscode.Uri) {
return !!uri.path && uri.path.toLowerCase().endsWith("pom.xml");
}
6 changes: 0 additions & 6 deletions src/recommendation/handler.ts

This file was deleted.

69 changes: 0 additions & 69 deletions src/recommendation/handlerImpl.ts

This file was deleted.

Loading

0 comments on commit 31399dd

Please sign in to comment.