diff --git a/extensions/ql-vscode/CHANGELOG.md b/extensions/ql-vscode/CHANGELOG.md index 2cafd773c..ed1ea2557 100644 --- a/extensions/ql-vscode/CHANGELOG.md +++ b/extensions/ql-vscode/CHANGELOG.md @@ -3,6 +3,7 @@ ## [UNRELEASED] - Fix a bug where database upgrades could not be resolved if some of the target pack's dependencies are outside of the workspace. [#1138](https://github.com/github/vscode-codeql/pull/1138) +- Fix a bug where queries took a long time to run if there are no folders in the workspace. [#1157](https://github.com/github/vscode-codeql/pull/1157) ## 1.5.11 - 10 February 2022 diff --git a/extensions/ql-vscode/src/cli.ts b/extensions/ql-vscode/src/cli.ts index c4c34d159..370cf8618 100644 --- a/extensions/ql-vscode/src/cli.ts +++ b/extensions/ql-vscode/src/cli.ts @@ -514,8 +514,7 @@ export class CodeQLCliServer implements Disposable { async resolveLibraryPath(workspaces: string[], queryPath: string): Promise { const subcommandArgs = [ '--query', queryPath, - '--additional-packs', - workspaces.join(path.delimiter) + ...this.getAdditionalPacksArg(workspaces) ]; return await this.runJsonCodeQlCliCommand(['resolve', 'library-path'], subcommandArgs, 'Resolving library paths'); } @@ -528,8 +527,7 @@ export class CodeQLCliServer implements Disposable { const subcommandArgs = [ '--format', 'bylanguage', queryUri.fsPath, - '--additional-packs', - workspaces.join(path.delimiter) + ...this.getAdditionalPacksArg(workspaces) ]; return JSON.parse(await this.runCodeQlCliCommand(['resolve', 'queries'], subcommandArgs, 'Resolving query by language')); } @@ -584,7 +582,7 @@ export class CodeQLCliServer implements Disposable { ): AsyncGenerator { const subcommandArgs = this.cliConfig.additionalTestArguments.concat([ - '--additional-packs', workspaces.join(path.delimiter), + ...this.getAdditionalPacksArg(workspaces), '--threads', this.cliConfig.numberTestThreads.toString(), ...testPaths @@ -606,8 +604,12 @@ export class CodeQLCliServer implements Disposable { /** Resolves the ML models that should be available when evaluating a query. */ async resolveMlModels(additionalPacks: string[]): Promise { - return await this.runJsonCodeQlCliCommand(['resolve', 'ml-models'], ['--additional-packs', - additionalPacks.join(path.delimiter)], 'Resolving ML models', false); + return await this.runJsonCodeQlCliCommand( + ['resolve', 'ml-models'], + this.getAdditionalPacksArg(additionalPacks), + 'Resolving ML models', + false + ); } /** @@ -772,7 +774,7 @@ export class CodeQLCliServer implements Disposable { * @returns A list of database upgrade script directories */ async resolveUpgrades(dbScheme: string, searchPath: string[], allowDowngradesIfPossible: boolean, targetDbScheme?: string): Promise { - const args = ['--additional-packs', searchPath.join(path.delimiter), '--dbscheme', dbScheme]; + const args = [...this.getAdditionalPacksArg(searchPath), '--dbscheme', dbScheme]; if (targetDbScheme) { args.push('--target-dbscheme', targetDbScheme); if (allowDowngradesIfPossible && await this.cliConstraints.supportsDowngrades()) { @@ -794,7 +796,7 @@ export class CodeQLCliServer implements Disposable { * @returns A dictionary mapping qlpack name to the directory it comes from */ resolveQlpacks(additionalPacks: string[], searchPath?: string[]): Promise { - const args = ['--additional-packs', additionalPacks.join(path.delimiter)]; + const args = this.getAdditionalPacksArg(additionalPacks); if (searchPath?.length) { args.push('--search-path', path.join(...searchPath)); } @@ -840,7 +842,7 @@ export class CodeQLCliServer implements Disposable { * @returns A list of query files found. */ async resolveQueriesInSuite(suite: string, additionalPacks: string[], searchPath?: string[]): Promise { - const args = ['--additional-packs', additionalPacks.join(path.delimiter)]; + const args = this.getAdditionalPacksArg(additionalPacks); if (searchPath !== undefined) { args.push('--search-path', path.join(...searchPath)); } @@ -873,8 +875,7 @@ export class CodeQLCliServer implements Disposable { '-o', outputPath, dir, - '--additional-packs', - workspaceFolders.join(path.delimiter) + ...this.getAdditionalPacksArg(workspaceFolders) ]; if (!precompile && await this.cliConstraints.supportsNoPrecompile()) { args.push('--no-precompile'); @@ -929,6 +930,12 @@ export class CodeQLCliServer implements Disposable { throw new Error('No distribution found'); } } + + private getAdditionalPacksArg(paths: string[]): string[] { + return paths.length + ? ['--additional-packs', paths.join(path.delimiter)] + : []; + } } /**