@@ -8,44 +8,48 @@ export function activate(context: vscode.ExtensionContext) {
88 let disposable = vscode . commands . registerCommand ( 'codacy-cli-integration.runCodacyCli' , ( ) => {
99 vscode . window . showInformationMessage ( 'Codacy CLI has been launched!' ) ;
1010
11-
11+
1212 if ( vscode . workspace . workspaceFolders !== undefined && vscode . workspace . workspaceFolders . length > 0 ) {
1313 let configuration = vscode . workspace . getConfiguration ( "codacy-cli" ) ;
14- const env : any = { env : { ...process . env } }
15- let additionalParameters = [ ]
14+ const env : any = { env : { ...process . env } } ;
15+ let additionalParameters = [ ] ;
1616 let diagnosticMap : Map < string , vscode . Diagnostic [ ] > = new Map ( ) ;
1717
1818 //if user has api-token, it also needs to have 'provider', 'username' and 'project'
1919 if ( configuration . has ( 'api-token' ) ) {
2020 if ( configuration . has ( 'provider' ) && configuration . has ( 'username' ) && configuration . has ( 'project' ) ) {
21- env . env [ 'CODACY_API_TOKEN' ] = configuration . get ( 'api-token' )
21+ env . env [ 'CODACY_API_TOKEN' ] = configuration . get ( 'api-token' ) ;
2222 additionalParameters . push ( `--provider ${ configuration . get ( 'provider' ) } ` ) ;
2323 additionalParameters . push ( `--username ${ configuration . get ( 'username' ) } ` ) ;
2424 additionalParameters . push ( `--project ${ configuration . get ( 'project' ) } ` ) ;
2525 } else {
2626 vscode . window . showErrorMessage ( 'You have an api-token but no provider, username or project so CLI will not consider the token' ) ;
2727 }
2828 } else if ( configuration . has ( 'project-token' ) ) {
29- env . env [ 'CODACY_PROJECT_TOKEN' ] = configuration . get ( 'project-token' )
29+ env . env [ 'CODACY_PROJECT_TOKEN' ] = configuration . get ( 'project-token' ) ;
30+ }
31+
32+ if ( configuration . has ( 'codacy-api-base-url' ) ) {
33+ env . env [ 'env.CODACY_API_BASE_URL' ] = configuration . get ( 'codacy-api-base-url' ) ;
3034 }
3135
32- if ( configuration . has ( 'codacy-api-base-url ' ) ) {
33- env . env [ 'env.CODACY_API_BASE_URL' ] = configuration . get ( 'codacy-api-base-url' )
36+ if ( configuration . has ( 'tool ' ) ) {
37+ additionalParameters . push ( `--tool ${ configuration . get ( 'tool' ) } ` ) ;
3438 }
3539
3640 for ( let i = 0 ; i < vscode . workspace . workspaceFolders . length ; i ++ ) {
3741 let workspaceFolder = vscode . workspace . workspaceFolders [ i ] . uri . path ;
38- env . env [ 'CODACY_CODE' ] = workspaceFolder
39- const dockerCommand = `docker run --rm=true --env CODACY_CODE="$CODACY_CODE" --volume /var/run/docker.sock:/var/run/docker.sock --volume "$CODACY_CODE":"$CODACY_CODE" --volume /tmp:/tmp codacy/codacy-analysis-cli analyze --format sarif ${ additionalParameters . join ( ' ' ) } `
40- const cp = require ( 'child_process' )
42+ env . env [ 'CODACY_CODE' ] = workspaceFolder ;
43+ const dockerCommand = `docker run --rm=true --env CODACY_CODE="$CODACY_CODE" --volume /var/run/docker.sock:/var/run/docker.sock --volume "$CODACY_CODE":"$CODACY_CODE" --volume /tmp:/tmp codacy/codacy-analysis-cli analyze --format sarif ${ additionalParameters . join ( ' ' ) } ` ;
44+ const cp = require ( 'child_process' ) ;
4145 cp . exec (
4246 dockerCommand ,
4347 env ,
4448 ( err : any , stdout : string , stderr : string ) => {
45- if ( err && err . code != 102 ) {
49+ if ( err && err . code !== 102 ) {
4650 vscode . window . showErrorMessage ( `Codacy CLI failed due to ${ err . message } ` ) ;
4751 console . log ( 'error: ' + err ) ;
48- return
52+ return ;
4953 }
5054 let sarifReport = JSON . parse ( stdout ) ;
5155
@@ -64,21 +68,22 @@ export function activate(context: vscode.ExtensionContext) {
6468 } ) ;
6569
6670 } ) ;
71+ diagnosticCollection . clear ( ) ;
6772 diagnosticMap . forEach ( ( diags , file ) => {
6873 diagnosticCollection . set ( vscode . Uri . parse ( file ) , diags ) ;
6974 } ) ;
7075 } ) ;
7176 }
7277
7378
74- } else {
79+ } else {
7580 vscode . window . showErrorMessage ( 'There are no workspaces to analyze!' ) ;
7681 return ;
7782 }
7883
7984
8085
81-
86+
8287 } ) ;
8388
8489 context . subscriptions . push ( disposable ) ;
0 commit comments