Skip to content

Commit 24b7adf

Browse files
committed
Allow cancelling pack download
1 parent 97eaaac commit 24b7adf

5 files changed

Lines changed: 17 additions & 8 deletions

File tree

extensions/ql-vscode/src/codeql-cli/cli.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -480,12 +480,7 @@ export class CodeQLCliServer implements Disposable {
480480
});
481481

482482
return await this.handleProcessOutput(process, {
483-
handleNullTerminator: true,
484-
onListenStart: (process) => {
485-
// Write the command followed by a null terminator.
486-
process.stdin.write(JSON.stringify(args), "utf8");
487-
process.stdin.write(this.nullBuffer);
488-
},
483+
handleNullTerminator: false,
489484
description,
490485
args,
491486
silent,
@@ -1587,12 +1582,20 @@ export class CodeQLCliServer implements Disposable {
15871582
/**
15881583
* Downloads a specified pack.
15891584
* @param packs The `<package-scope/name[@version]>` of the packs to download.
1585+
* @param token The cancellation token. If not specified, the command will be run in the CLI server.
15901586
*/
1591-
async packDownload(packs: string[]): Promise<PackDownloadResult> {
1587+
async packDownload(
1588+
packs: string[],
1589+
token?: CancellationToken,
1590+
): Promise<PackDownloadResult> {
15921591
return this.runJsonCodeQlCliCommandWithAuthentication(
15931592
["pack", "download"],
15941593
packs,
15951594
"Downloading packs",
1595+
{
1596+
runInNewProcess: !!token, // Only run in a new process if a token is provided
1597+
token,
1598+
},
15961599
);
15971600
}
15981601

extensions/ql-vscode/src/model-editor/model-evaluator.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export class ModelEvaluator extends DisposableObject {
5858
this.app.logger,
5959
this.cliServer,
6060
this.language,
61+
this.cancellationSource.token,
6162
);
6263

6364
if (!qlPack) {

extensions/ql-vscode/src/variant-analysis/code-scanning-pack.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,18 @@ import type { QlPackDetails } from "./ql-pack-details";
99
import { getQlPackFilePath } from "../common/ql";
1010
import type { SuiteInstruction } from "../packaging/suite-instruction";
1111
import { SARIF_RESULTS_QUERY_KINDS } from "../common/query-metadata";
12+
import type { CancellationToken } from "vscode";
1213

1314
export async function resolveCodeScanningQueryPack(
1415
logger: BaseLogger,
1516
cliServer: CodeQLCliServer,
1617
language: QueryLanguage,
18+
token: CancellationToken,
1719
): Promise<QlPackDetails> {
1820
// Get pack
1921
void logger.log(`Downloading pack for language: ${language}`);
2022
const packName = `codeql/${language}-queries`;
21-
const packDownloadResult = await cliServer.packDownload([packName]);
23+
const packDownloadResult = await cliServer.packDownload([packName], token);
2224
const downloadedPack = packDownloadResult.packs[0];
2325

2426
const packDir = join(

extensions/ql-vscode/src/variant-analysis/variant-analysis-manager.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ export class VariantAnalysisManager
245245
this.app.logger,
246246
this.cliServer,
247247
language,
248+
token,
248249
);
249250

250251
await this.runVariantAnalysis(

extensions/ql-vscode/test/vscode-tests/cli-integration/variant-analysis/code-scanning-pack.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { CancellationTokenSource } from "vscode";
12
import type { CodeQLCliServer } from "../../../../src/codeql-cli/cli";
23
import type { App } from "../../../../src/common/app";
34
import { QueryLanguage } from "../../../../src/common/query-language";
@@ -20,6 +21,7 @@ describe("Code Scanning pack", () => {
2021
app.logger,
2122
cli,
2223
QueryLanguage.Javascript,
24+
new CancellationTokenSource().token,
2325
);
2426
// Should include queries. Just check that at least one known query exists.
2527
// It doesn't particularly matter which query we check for.

0 commit comments

Comments
 (0)