Skip to content

Commit 019af98

Browse files
authored
Merge pull request #2171 from github/koesie10/commands-with-progress
Convert run variant analysis command to new commands package
2 parents c632c38 + c853baf commit 019af98

3 files changed

Lines changed: 34 additions & 53 deletions

File tree

extensions/ql-vscode/src/common/commands.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { CommandManager } from "../packages/commands";
2+
import type { Uri } from "vscode";
23

34
/**
45
* Contains type definitions for all commands used by the extension.
@@ -17,6 +18,8 @@ export type VariantAnalysisCommands = {
1718
"codeQL.openVariantAnalysisLogs": (
1819
variantAnalysisId: number,
1920
) => Promise<void>;
21+
"codeQL.runVariantAnalysis": (uri?: Uri) => Promise<void>;
22+
"codeQL.runVariantAnalysisContextEditor": (uri?: Uri) => Promise<void>;
2023
};
2124

2225
export type AllCommands = BaseCommands & VariantAnalysisCommands;

extensions/ql-vscode/src/extension.ts

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,39 +1092,6 @@ async function activateWithInstalledDistribution(
10921092
),
10931093
);
10941094

1095-
ctx.subscriptions.push(
1096-
commandRunnerWithProgress(
1097-
"codeQL.runVariantAnalysis",
1098-
async (
1099-
progress: ProgressCallback,
1100-
token: CancellationToken,
1101-
uri: Uri | undefined,
1102-
) =>
1103-
await runVariantAnalysis(variantAnalysisManager, progress, token, uri),
1104-
{
1105-
title: "Run Variant Analysis",
1106-
cancellable: true,
1107-
},
1108-
),
1109-
);
1110-
1111-
// Since we are tracking extension usage through commands, this command mirrors the "codeQL.runVariantAnalysis" command
1112-
ctx.subscriptions.push(
1113-
commandRunnerWithProgress(
1114-
"codeQL.runVariantAnalysisContextEditor",
1115-
async (
1116-
progress: ProgressCallback,
1117-
token: CancellationToken,
1118-
uri: Uri | undefined,
1119-
) =>
1120-
await runVariantAnalysis(variantAnalysisManager, progress, token, uri),
1121-
{
1122-
title: "Run Variant Analysis",
1123-
cancellable: true,
1124-
},
1125-
),
1126-
);
1127-
11281095
const allCommands: AllCommands = {
11291096
...getCommands(),
11301097
...variantAnalysisManager.getCommands(),
@@ -1891,25 +1858,6 @@ async function openReferencedFile(
18911858
}
18921859
}
18931860

1894-
async function runVariantAnalysis(
1895-
variantAnalysisManager: VariantAnalysisManager,
1896-
progress: ProgressCallback,
1897-
token: CancellationToken,
1898-
uri: Uri | undefined,
1899-
): Promise<void> {
1900-
progress({
1901-
maxStep: 5,
1902-
step: 0,
1903-
message: "Getting credentials",
1904-
});
1905-
1906-
await variantAnalysisManager.runVariantAnalysis(
1907-
uri || window.activeTextEditor?.document.uri,
1908-
progress,
1909-
token,
1910-
);
1911-
}
1912-
19131861
async function viewAst(
19141862
astViewer: AstViewer,
19151863
printAstTemplateProvider: TemplatePrintAstProvider,

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

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ import {
5151
import { readFile, readJson, remove, pathExists, outputJson } from "fs-extra";
5252
import { EOL } from "os";
5353
import { cancelVariantAnalysis } from "./gh-api/gh-actions-api-client";
54-
import { ProgressCallback, UserCancellationException } from "../commandRunner";
54+
import {
55+
ProgressCallback,
56+
UserCancellationException,
57+
withProgress,
58+
} from "../commandRunner";
5559
import { CodeQLCliServer } from "../cli";
5660
import {
5761
defaultFilterSortState,
@@ -129,18 +133,44 @@ export class VariantAnalysisManager
129133
"codeQL.openVariantAnalysisLogs": async (variantAnalysisId: number) => {
130134
await this.openVariantAnalysisLogs(variantAnalysisId);
131135
},
136+
"codeQL.runVariantAnalysis": async (uri?: Uri) =>
137+
this.runVariantAnalysisFromCommand(uri),
138+
// Since we are tracking extension usage through commands, this command mirrors the "codeQL.runVariantAnalysis" command
139+
"codeQL.runVariantAnalysisContextEditor": async (uri?: Uri) =>
140+
this.runVariantAnalysisFromCommand(uri),
132141
};
133142
}
134143

135144
get commandManager(): AppCommandManager {
136145
return this.app.commands;
137146
}
138147

148+
private async runVariantAnalysisFromCommand(uri?: Uri) {
149+
return withProgress(
150+
async (progress, token) =>
151+
this.runVariantAnalysis(
152+
uri || Window.activeTextEditor?.document.uri,
153+
progress,
154+
token,
155+
),
156+
{
157+
title: "Run Variant Analysis",
158+
cancellable: true,
159+
},
160+
);
161+
}
162+
139163
public async runVariantAnalysis(
140164
uri: Uri | undefined,
141165
progress: ProgressCallback,
142166
token: CancellationToken,
143167
): Promise<void> {
168+
progress({
169+
maxStep: 5,
170+
step: 0,
171+
message: "Getting credentials",
172+
});
173+
144174
const {
145175
actionBranch,
146176
base64Pack,

0 commit comments

Comments
 (0)