2
2
3
3
'use strict' ;
4
4
5
+ import { IRecommendationService , Recommendation } from "@redhat-developer/vscode-extension-proposals/lib" ;
5
6
import * as vscode from "vscode" ;
6
- import { IHandler } from "./handler" ;
7
7
8
8
const EXTENSION_NAME = "redhat.fabric8-analytics" ;
9
9
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 ] ;
15
15
}
16
16
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
+ }
30
22
23
+ async function delayedShowDependencyRecommendation ( context : vscode . ExtensionContext , recommendService : IRecommendationService ) : Promise < void > {
24
+ await new Promise ( f => setTimeout ( f , 6000 ) ) ;
31
25
const isPomDotXmlOpened = vscode . workspace . textDocuments . findIndex ( doc => isPomDotXml ( doc . uri ) ) !== - 1 ;
32
26
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
+ } ) ) ;
34
38
}
35
39
}
40
+
41
+ function isPomDotXml ( uri : vscode . Uri ) {
42
+ return ! ! uri . path && uri . path . toLowerCase ( ) . endsWith ( "pom.xml" ) ;
43
+ }
0 commit comments