Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions extensions/ql-vscode/src/common/commands.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { CommandManager } from "../packages/commands";
import type { Uri } from "vscode";
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd have preferred to not import from vscode in the src/common directory, but importing a type should be fine. We could also create an interface that defines the necessary properties to avoid importing from vscode here, but we'd need to find out which methods on Uri in command arguments are being used. For this command, it's just fsPath, but for others there may be more.


/**
* Contains type definitions for all commands used by the extension.
Expand All @@ -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;
Expand Down
52 changes: 0 additions & 52 deletions extensions/ql-vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -129,18 +133,44 @@ 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),
};
}

get commandManager(): AppCommandManager {
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,
Expand Down