Merge pull request #2171 from github/koesie10/commands-with-progress

Convert run variant analysis command to new commands package
This commit is contained in:
Koen Vlaswinkel
2023-03-15 16:39:35 +01:00
committed by GitHub
3 changed files with 34 additions and 53 deletions

View File

@@ -1,4 +1,5 @@
import { CommandManager } from "../packages/commands";
import type { Uri } from "vscode";
/**
* Contains type definitions for all commands used by the extension.
@@ -17,6 +18,8 @@ export type VariantAnalysisCommands = {
"codeQL.openVariantAnalysisLogs": (
variantAnalysisId: number,
) => Promise<void>;
"codeQL.runVariantAnalysis": (uri?: Uri) => Promise<void>;
"codeQL.runVariantAnalysisContextEditor": (uri?: Uri) => Promise<void>;
};
export type AllCommands = BaseCommands & VariantAnalysisCommands;

View File

@@ -1092,39 +1092,6 @@ async function activateWithInstalledDistribution(
),
);
ctx.subscriptions.push(
commandRunnerWithProgress(
"codeQL.runVariantAnalysis",
async (
progress: ProgressCallback,
token: CancellationToken,
uri: Uri | undefined,
) =>
await runVariantAnalysis(variantAnalysisManager, progress, token, uri),
{
title: "Run Variant Analysis",
cancellable: true,
},
),
);
// Since we are tracking extension usage through commands, this command mirrors the "codeQL.runVariantAnalysis" command
ctx.subscriptions.push(
commandRunnerWithProgress(
"codeQL.runVariantAnalysisContextEditor",
async (
progress: ProgressCallback,
token: CancellationToken,
uri: Uri | undefined,
) =>
await runVariantAnalysis(variantAnalysisManager, progress, token, uri),
{
title: "Run Variant Analysis",
cancellable: true,
},
),
);
const allCommands: AllCommands = {
...getCommands(),
...variantAnalysisManager.getCommands(),
@@ -1891,25 +1858,6 @@ async function openReferencedFile(
}
}
async function runVariantAnalysis(
variantAnalysisManager: VariantAnalysisManager,
progress: ProgressCallback,
token: CancellationToken,
uri: Uri | undefined,
): Promise<void> {
progress({
maxStep: 5,
step: 0,
message: "Getting credentials",
});
await variantAnalysisManager.runVariantAnalysis(
uri || window.activeTextEditor?.document.uri,
progress,
token,
);
}
async function viewAst(
astViewer: AstViewer,
printAstTemplateProvider: TemplatePrintAstProvider,

View File

@@ -51,7 +51,11 @@ import {
import { readFile, readJson, remove, pathExists, outputJson } from "fs-extra";
import { EOL } from "os";
import { cancelVariantAnalysis } from "./gh-api/gh-actions-api-client";
import { ProgressCallback, UserCancellationException } from "../commandRunner";
import {
ProgressCallback,
UserCancellationException,
withProgress,
} from "../commandRunner";
import { CodeQLCliServer } from "../cli";
import {
defaultFilterSortState,
@@ -129,6 +133,11 @@ export class VariantAnalysisManager
"codeQL.openVariantAnalysisLogs": async (variantAnalysisId: number) => {
await this.openVariantAnalysisLogs(variantAnalysisId);
},
"codeQL.runVariantAnalysis": async (uri?: Uri) =>
this.runVariantAnalysisFromCommand(uri),
// Since we are tracking extension usage through commands, this command mirrors the "codeQL.runVariantAnalysis" command
"codeQL.runVariantAnalysisContextEditor": async (uri?: Uri) =>
this.runVariantAnalysisFromCommand(uri),
};
}
@@ -136,11 +145,32 @@ export class VariantAnalysisManager
return this.app.commands;
}
private async runVariantAnalysisFromCommand(uri?: Uri) {
return withProgress(
async (progress, token) =>
this.runVariantAnalysis(
uri || Window.activeTextEditor?.document.uri,
progress,
token,
),
{
title: "Run Variant Analysis",
cancellable: true,
},
);
}
public async runVariantAnalysis(
uri: Uri | undefined,
progress: ProgressCallback,
token: CancellationToken,
): Promise<void> {
progress({
maxStep: 5,
step: 0,
message: "Getting credentials",
});
const {
actionBranch,
base64Pack,