@@ -94,6 +94,7 @@ import { getQlPackFilePath } from "../common/ql";
9494import { tryGetQueryMetadata } from "../codeql-cli/query-metadata" ;
9595import { getOnDiskWorkspaceFolders } from "../common/vscode/workspace-folders" ;
9696import { findVariantAnalysisQlPackRoot } from "./ql" ;
97+ import { resolveCodeScanningQueryPack } from "./code-scanning-pack" ;
9798
9899const maxRetryCount = 3 ;
99100
@@ -219,7 +220,7 @@ export class VariantAnalysisManager
219220 public async runVariantAnalysisFromPublishedPack ( ) : Promise < void > {
220221 return withProgress ( async ( progress , token ) => {
221222 progress ( {
222- maxStep : 8 ,
223+ maxStep : 7 ,
223224 step : 0 ,
224225 message : "Determining query language" ,
225226 } ) ;
@@ -230,53 +231,17 @@ export class VariantAnalysisManager
230231 }
231232
232233 progress ( {
233- maxStep : 8 ,
234- step : 1 ,
235- message : "Downloading query pack" ,
236- } ) ;
237-
238- const packName = `codeql/${ language } -queries` ;
239- const packDownloadResult = await this . cliServer . packDownload ( [ packName ] ) ;
240- const downloadedPack = packDownloadResult . packs [ 0 ] ;
241-
242- const packDir = join (
243- packDownloadResult . packDir ,
244- downloadedPack . name ,
245- downloadedPack . version ,
246- ) ;
247-
248- progress ( {
249- maxStep : 8 ,
234+ maxStep : 7 ,
250235 step : 2 ,
251- message : "Resolving queries in pack" ,
236+ message : "Downloading query pack and resolving queries " ,
252237 } ) ;
253238
254- const suitePath = join (
255- packDir ,
256- "codeql-suites" ,
257- `${ language } -code-scanning.qls` ,
258- ) ;
259- const resolvedQueries = await this . cliServer . resolveQueries ( suitePath ) ;
260-
261- const problemQueries =
262- await this . filterToOnlyProblemQueries ( resolvedQueries ) ;
263-
264- if ( problemQueries . length === 0 ) {
265- void this . app . logger . showErrorMessage (
266- `Unable to trigger variant analysis. No problem queries found in published query pack: ${ packName } .` ,
267- ) ;
268- return ;
269- }
270-
271- const qlPackFilePath = await getQlPackFilePath ( packDir ) ;
272-
273239 // Build up details to pass to the functions that run the variant analysis.
274- const qlPackDetails : QlPackDetails = {
275- queryFiles : problemQueries ,
276- qlPackRootPath : packDir ,
277- qlPackFilePath,
240+ const qlPackDetails = await resolveCodeScanningQueryPack (
241+ this . app . logger ,
242+ this . cliServer ,
278243 language ,
279- } ;
244+ ) ;
280245
281246 await this . runVariantAnalysis (
282247 qlPackDetails ,
@@ -291,24 +256,6 @@ export class VariantAnalysisManager
291256 } ) ;
292257 }
293258
294- private async filterToOnlyProblemQueries (
295- queries : string [ ] ,
296- ) : Promise < string [ ] > {
297- const problemQueries : string [ ] = [ ] ;
298- for ( const query of queries ) {
299- const queryMetadata = await this . cliServer . resolveMetadata ( query ) ;
300- if (
301- queryMetadata . kind === "problem" ||
302- queryMetadata . kind === "path-problem"
303- ) {
304- problemQueries . push ( query ) ;
305- } else {
306- void this . app . logger . log ( `Skipping non-problem query ${ query } ` ) ;
307- }
308- }
309- return problemQueries ;
310- }
311-
312259 private async runVariantAnalysisCommand ( queryFiles : Uri [ ] ) : Promise < void > {
313260 if ( queryFiles . length === 0 ) {
314261 throw new Error ( "Please select a .ql file to run as a variant analysis" ) ;
0 commit comments