Skip to content

Commit 02deb55

Browse files
authored
Use vscode-extension-proposals to unify proposal logic (#3101)
- Use newest extension-proposals 0.0.21 - Fixes #3099 Signed-off-by: Rob Stryker <[email protected]>
1 parent bd03b35 commit 02deb55

File tree

8 files changed

+126
-182
lines changed

8 files changed

+126
-182
lines changed

package-lock.json

Lines changed: 81 additions & 78 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,6 +1469,7 @@
14691469
"@vscode/webview-ui-toolkit": "1.2.2",
14701470
"chokidar": "^3.5.3",
14711471
"@redhat-developer/vscode-redhat-telemetry": "^0.6.1",
1472+
"@redhat-developer/vscode-extension-proposals": "0.0.21",
14721473
"expand-home-dir": "^0.0.3",
14731474
"fmtr": "^1.1.2",
14741475
"fs-extra": "^8.1.0",

src/extension.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import { convertToGlob, deleteDirectory, ensureExists, getBuildFilePatterns, get
3333
import glob = require('glob');
3434
import { Telemetry } from './telemetry';
3535
import { getMessage } from './errorUtils';
36+
import { TelemetryService } from '@redhat-developer/vscode-redhat-telemetry/lib';
3637

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

104-
Telemetry.startTelemetry(context);
105+
const telemetryService: Promise<TelemetryService> = Telemetry.startTelemetry(context);
105106

106107
enableJavadocSymbols();
107108

108-
initializeRecommendation(context);
109+
initializeRecommendation(context, telemetryService);
109110

110111
registerOutOfMemoryDetection(storagePath);
111112

src/recommendation/dependencyAnalytics.ts

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,42 @@
22

33
'use strict';
44

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

88
const EXTENSION_NAME = "redhat.fabric8-analytics";
99
const GH_ORG_URL = `https://github.com/fabric8-analytics`;
10-
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?`;
11-
const JAVA_DEPENDENCY_ANALYTICS_SHOW = "java.recommendations.dependency.analytics.show";
12-
13-
function isPomDotXml(uri: vscode.Uri) {
14-
return !!uri.path && uri.path.toLowerCase().endsWith("pom.xml");
10+
let alreadyShown = false;
11+
export function initialize (context: vscode.ExtensionContext, recommendService: IRecommendationService): Recommendation[] {
12+
const ret: Recommendation = createDependencyRecommendation(recommendService);
13+
delayedShowDependencyRecommendation(context, recommendService);
14+
return [ret];
1515
}
1616

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

23+
async function delayedShowDependencyRecommendation (context: vscode.ExtensionContext, recommendService: IRecommendationService): Promise<void> {
24+
await new Promise(f => setTimeout(f, 6000));
3125
const isPomDotXmlOpened = vscode.workspace.textDocuments.findIndex(doc => isPomDotXml(doc.uri)) !== -1;
3226
if (isPomDotXmlOpened) {
33-
handler.handle(EXTENSION_NAME, RECOMMENDATION_MESSAGE);
27+
recommendService.show(EXTENSION_NAME);
28+
} else {
29+
context.subscriptions.push(vscode.workspace.onDidOpenTextDocument(e => {
30+
// I would prefer to delete this listener after showing once, but i can't figure out how ;)
31+
if( !alreadyShown ) {
32+
if (isPomDotXml(e.uri)) {
33+
recommendService.show(EXTENSION_NAME);
34+
alreadyShown = true;
35+
}
36+
}
37+
}));
3438
}
3539
}
40+
41+
function isPomDotXml(uri: vscode.Uri) {
42+
return !!uri.path && uri.path.toLowerCase().endsWith("pom.xml");
43+
}

src/recommendation/handler.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/recommendation/handlerImpl.ts

Lines changed: 0 additions & 69 deletions
This file was deleted.

0 commit comments

Comments
 (0)