11import { CodeQLCliServer } from './cli' ;
2- import * as fs from 'fs-extra' ;
3- import * as path from 'path' ;
42import {
53 getOnDiskWorkspaceFolders ,
64 showAndLogErrorMessage ,
75 showAndLogInformationMessage ,
6+ showAndLogWarningMessage ,
87} from './helpers' ;
9- import { window } from 'vscode' ;
10- import { ProgressCallback } from './commandRunner' ;
8+ import { QuickPickItem , window } from 'vscode' ;
9+ import { ProgressCallback , UserCancellationException } from './commandRunner' ;
10+ import { logger } from './logging' ;
1111
12- const CORE_PACKS = [
13- 'codeql/cpp-all' ,
14- 'codeql/csharp-all' ,
15- 'codeql/go-all' ,
16- 'codeql/java-all' ,
17- 'codeql/javascript-all' ,
18- 'codeql/python-all' ,
19- 'codeql/ruby-all' ,
12+ const QUERY_PACKS = [
13+ 'codeql/cpp-queries' ,
14+ 'codeql/csharp-queries' ,
15+ 'codeql/go-queries' ,
16+ 'codeql/java-queries' ,
17+ 'codeql/javascript-queries' ,
18+ 'codeql/python-queries' ,
19+ 'codeql/ruby-queries' ,
20+ 'codeql/csharp-solorigate-queries' ,
21+ 'codeql/javascript-experimental-atm-queries' ,
2022] ;
2123
22- /**
23- * Lists all workspace folders that contain a qlpack.yml file.
24- *
25- * Note: This currently only finds packs at the root of a workspace folder.
26- * TODO: Add support for packs in subfolders.
27- */
28- function getWorkspacePacks ( ) : string [ ] {
29- const packs : string [ ] = [ ] ;
30- const workspaceFolders = getOnDiskWorkspaceFolders ( ) ;
31- for ( const folder of workspaceFolders ) {
32- const qlpackYml = path . join ( folder , 'qlpack.yml' ) ;
33- if ( fs . pathExistsSync ( qlpackYml ) ) {
34- packs . push ( folder ) ;
35- }
36- }
37- return packs ;
38- }
39-
4024/**
4125 * Prompts user to choose packs to download, and downloads them.
4226 *
@@ -53,14 +37,14 @@ export async function handleDownloadPacks(
5337 maxStep : 2 ,
5438 } ) ;
5539 let packsToDownload : string [ ] = [ ] ;
56- const corePackOption = 'Download core CodeQL packs' ;
40+ const queryPackOption = 'Download core query packs' ;
5741 const customPackOption = 'Download custom specified pack' ;
5842 const quickpick = await window . showQuickPick (
59- [ corePackOption , customPackOption ] ,
43+ [ queryPackOption , customPackOption ] ,
6044 { ignoreFocusOut : true }
6145 ) ;
62- if ( quickpick === corePackOption ) {
63- packsToDownload = CORE_PACKS ;
46+ if ( quickpick === queryPackOption ) {
47+ packsToDownload = QUERY_PACKS ;
6448 } else if ( quickpick === customPackOption ) {
6549 const customPack = await window . showInputBox ( {
6650 prompt :
@@ -70,26 +54,30 @@ export async function handleDownloadPacks(
7054 if ( customPack ) {
7155 packsToDownload . push ( customPack ) ;
7256 } else {
73- void showAndLogErrorMessage ( 'No pack specified.' ) ;
57+ throw new UserCancellationException ( 'No pack specified.' ) ;
7458 }
7559 }
7660 if ( packsToDownload && packsToDownload . length > 0 ) {
7761 progress ( {
78- message : ` Downloading ${ packsToDownload . join ( ', ' ) } ` ,
62+ message : ' Downloading packs. This may take a few minutes.' ,
7963 step : 2 ,
8064 maxStep : 2 ,
8165 } ) ;
82- for ( const pack of packsToDownload ) {
83- try {
84- await cliServer . packDownload ( pack ) ;
85- } catch ( error ) {
86- void showAndLogErrorMessage ( `Unable to download pack ${ pack } . See logs for more details.` ) ;
87- }
66+ try {
67+ await cliServer . packDownload ( packsToDownload ) ;
68+ void showAndLogInformationMessage ( 'Finished downloading packs.' ) ;
69+ } catch ( error ) {
70+ void showAndLogErrorMessage (
71+ 'Unable to download all packs. See logs for more details.'
72+ ) ;
8873 }
89- void showAndLogInformationMessage ( 'Finished downloading packs.' ) ;
9074 }
9175}
9276
77+ interface QLPackQuickPickItem extends QuickPickItem {
78+ packRootDir : string [ ] ;
79+ }
80+
9381/**
9482 * Prompts user to choose packs to install, and installs them.
9583 *
@@ -105,40 +93,43 @@ export async function handleInstallPacks(
10593 step : 1 ,
10694 maxStep : 2 ,
10795 } ) ;
108- let packsToInstall : string [ ] = [ ] ;
109- const workspacePackOption = 'Install workspace packs' ;
110- const customPackOption = 'Install custom specified pack' ;
111- const quickpick = await window . showQuickPick (
112- [ workspacePackOption , customPackOption ] ,
113- { ignoreFocusOut : true }
114- ) ;
115- if ( quickpick === workspacePackOption ) {
116- packsToInstall = getWorkspacePacks ( ) ;
117- } else if ( quickpick === customPackOption ) {
118- const customPack = await window . showInputBox ( {
119- prompt :
120- 'Enter the root directory of the pack to install (as an absolute path)' ,
121- ignoreFocusOut : true ,
122- } ) ;
123- if ( customPack ) {
124- packsToInstall . push ( customPack ) ;
125- } else {
126- void showAndLogErrorMessage ( 'No pack specified.' ) ;
127- }
128- }
96+ const workspacePacks = await cliServer . resolveQlpacks ( getOnDiskWorkspaceFolders ( ) ) ;
97+ const quickPickItems = Object . entries ( workspacePacks ) . map < QLPackQuickPickItem > ( ( [ key , value ] ) => ( {
98+ label : key ,
99+ packRootDir : value ,
100+ } ) ) ;
101+ const packsToInstall = await window . showQuickPick ( quickPickItems , {
102+ placeHolder : 'Select packs to install' ,
103+ canPickMany : true ,
104+ ignoreFocusOut : true ,
105+ } ) ;
129106 if ( packsToInstall && packsToInstall . length > 0 ) {
130107 progress ( {
131- message : ` Installing ${ packsToInstall . join ( ', ' ) } ` ,
108+ message : ' Installing packs. This may take a few minutes.' ,
132109 step : 2 ,
133110 maxStep : 2 ,
134111 } ) ;
112+ const failedPacks = [ ] ;
113+ const errors = [ ] ;
135114 for ( const pack of packsToInstall ) {
136115 try {
137- await cliServer . packInstall ( pack ) ;
116+ for ( const dir of pack . packRootDir ) {
117+ await cliServer . packInstall ( dir ) ;
118+ }
138119 } catch ( error ) {
139- void showAndLogErrorMessage ( `Unable to install pack ${ pack } . See logs for more details.` ) ;
120+ failedPacks . push ( pack . label ) ;
121+ errors . push ( error ) ;
140122 }
141123 }
142- void showAndLogInformationMessage ( 'Finished installing packs.' ) ;
124+ if ( failedPacks . length > 0 ) {
125+ void logger . log ( `Errors:\n${ errors . join ( '\n' ) } ` ) ;
126+ void showAndLogWarningMessage (
127+ `Unable to install some packs: ${ failedPacks . join ( ', ' ) } . See logs for more details.`
128+ ) ;
129+ } else {
130+ void showAndLogInformationMessage ( 'Finished installing packs.' ) ;
131+ }
132+ } else {
133+ throw new UserCancellationException ( 'No packs selected.' ) ;
143134 }
144135}
0 commit comments