1- import { relative , resolve } from "path" ;
1+ import { relative , resolve , sep } from "path" ;
22import { pathExists , readFile } from "fs-extra" ;
33import { load as loadYaml } from "js-yaml" ;
44import { minimatch } from "minimatch" ;
@@ -9,14 +9,42 @@ import { ProgressCallback } from "../progress";
99import { DatabaseItem } from "../local-databases" ;
1010import { getQlPackPath , QLPACK_FILENAMES } from "../pure/ql" ;
1111
12- export async function pickExtensionPack (
13- cliServer : CodeQLCliServer ,
12+ const maxStep = 3 ;
13+
14+ export async function pickExtensionPackModelFile (
15+ cliServer : Pick < CodeQLCliServer , "resolveQlpacks" | "resolveExtensions" > ,
16+ databaseItem : Pick < DatabaseItem , "name" > ,
17+ progress : ProgressCallback ,
18+ token : CancellationToken ,
19+ ) : Promise < string | undefined > {
20+ const extensionPackPath = await pickExtensionPack ( cliServer , progress , token ) ;
21+ if ( ! extensionPackPath ) {
22+ return ;
23+ }
24+
25+ const modelFile = await pickModelFile (
26+ cliServer ,
27+ databaseItem ,
28+ extensionPackPath ,
29+ progress ,
30+ token ,
31+ ) ;
32+ if ( ! modelFile ) {
33+ return ;
34+ }
35+
36+ return modelFile ;
37+ }
38+
39+ async function pickExtensionPack (
40+ cliServer : Pick < CodeQLCliServer , "resolveQlpacks" > ,
1441 progress : ProgressCallback ,
42+ token : CancellationToken ,
1543) : Promise < string | undefined > {
1644 progress ( {
1745 message : "Resolving extension packs..." ,
1846 step : 1 ,
19- maxStep : 3 ,
47+ maxStep,
2048 } ) ;
2149
2250 // Get all existing extension packs in the workspace
@@ -30,12 +58,16 @@ export async function pickExtensionPack(
3058 progress ( {
3159 message : "Choosing extension pack..." ,
3260 step : 2 ,
33- maxStep : 3 ,
61+ maxStep,
3462 } ) ;
3563
36- const extensionPackOption = await window . showQuickPick ( options , {
37- title : "Select extension pack to use" ,
38- } ) ;
64+ const extensionPackOption = await window . showQuickPick (
65+ options ,
66+ {
67+ title : "Select extension pack to use" ,
68+ } ,
69+ token ,
70+ ) ;
3971 if ( ! extensionPackOption ) {
4072 return undefined ;
4173 }
@@ -44,19 +76,26 @@ export async function pickExtensionPack(
4476 if ( extensionPackPaths . length !== 1 ) {
4577 void showAndLogErrorMessage (
4678 `Extension pack ${ extensionPackOption . extensionPack } could not be resolved to a single location` ,
79+ {
80+ fullMessage : `Extension pack ${
81+ extensionPackOption . extensionPack
82+ } could not be resolved to a single location. Found ${
83+ extensionPackPaths . length
84+ } locations: ${ extensionPackPaths . join ( ", " ) } .`,
85+ } ,
4786 ) ;
4887 return undefined ;
4988 }
5089
5190 return extensionPackPaths [ 0 ] ;
5291}
5392
54- export async function pickModelFile (
55- cliServer : CodeQLCliServer ,
93+ async function pickModelFile (
94+ cliServer : Pick < CodeQLCliServer , "resolveExtensions" > ,
95+ databaseItem : Pick < DatabaseItem , "name" > ,
96+ extensionPackPath : string ,
5697 progress : ProgressCallback ,
5798 token : CancellationToken ,
58- databaseItem : DatabaseItem ,
59- extensionPackPath : string ,
6099) : Promise < string | undefined > {
61100 // Find the existing model files in the extension pack
62101 const additionalPacks = getOnDiskWorkspaceFolders ( ) ;
@@ -74,13 +113,13 @@ export async function pickModelFile(
74113 }
75114
76115 if ( modelFiles . size === 0 ) {
77- return pickNewModelFile ( token , databaseItem , extensionPackPath ) ;
116+ return pickNewModelFile ( databaseItem , extensionPackPath , token ) ;
78117 }
79118
80119 const fileOptions : Array < { label : string ; file : string | null } > = [ ] ;
81120 for ( const file of modelFiles ) {
82121 fileOptions . push ( {
83- label : relative ( extensionPackPath , file ) ,
122+ label : relative ( extensionPackPath , file ) . replaceAll ( sep , "/" ) ,
84123 file,
85124 } ) ;
86125 }
@@ -92,7 +131,7 @@ export async function pickModelFile(
92131 progress ( {
93132 message : "Choosing model file..." ,
94133 step : 3 ,
95- maxStep : 3 ,
134+ maxStep,
96135 } ) ;
97136
98137 const fileOption = await window . showQuickPick (
@@ -111,13 +150,13 @@ export async function pickModelFile(
111150 return fileOption . file ;
112151 }
113152
114- return pickNewModelFile ( token , databaseItem , extensionPackPath ) ;
153+ return pickNewModelFile ( databaseItem , extensionPackPath , token ) ;
115154}
116155
117156async function pickNewModelFile (
118- token : CancellationToken ,
119- databaseItem : DatabaseItem ,
157+ databaseItem : Pick < DatabaseItem , "name" > ,
120158 extensionPackPath : string ,
159+ token : CancellationToken ,
121160) {
122161 const qlpackPath = await getQlPackPath ( extensionPackPath ) ;
123162 if ( ! qlpackPath ) {
0 commit comments