Convert query editing commands to typed commands
This commit is contained in:
@@ -38,6 +38,18 @@ export type BaseCommands = {
|
||||
"codeQL.restartQueryServer": () => Promise<void>;
|
||||
};
|
||||
|
||||
// Commands used when working with queries in the editor
|
||||
export type QueryEditorCommands = {
|
||||
"codeQL.openReferencedFile": (selectedQuery: Uri) => Promise<void>;
|
||||
"codeQL.openReferencedFileContextEditor": (
|
||||
selectedQuery: Uri,
|
||||
) => Promise<void>;
|
||||
"codeQL.openReferencedFileContextExplorer": (
|
||||
selectedQuery: Uri,
|
||||
) => Promise<void>;
|
||||
"codeQL.previewQueryHelp": (selectedQuery: Uri) => Promise<void>;
|
||||
};
|
||||
|
||||
// Commands used for running local queries
|
||||
export type LocalQueryCommands = {
|
||||
"codeQL.runQuery": (uri?: Uri) => Promise<void>;
|
||||
@@ -213,6 +225,7 @@ export type MockGitHubApiServerCommands = {
|
||||
};
|
||||
|
||||
export type AllCommands = BaseCommands &
|
||||
QueryEditorCommands &
|
||||
ResultsViewCommands &
|
||||
QueryHistoryCommands &
|
||||
LocalDatabasesCommands &
|
||||
|
||||
@@ -120,7 +120,7 @@ import {
|
||||
showResultsForCompletedQuery,
|
||||
} from "./local-queries";
|
||||
import { getAstCfgCommands } from "./ast-cfg-commands";
|
||||
import { registerQueryEditorCommands } from "./query-editor";
|
||||
import { getQueryEditorCommands } from "./query-editor";
|
||||
|
||||
/**
|
||||
* extension.ts
|
||||
@@ -829,6 +829,11 @@ async function activateWithInstalledDistribution(
|
||||
|
||||
const allCommands: AllCommands = {
|
||||
...getCommands(cliServer, qs),
|
||||
...getQueryEditorCommands({
|
||||
queryRunner: qs,
|
||||
cliServer,
|
||||
qhelpTmpDir: qhelpTmpDir.name,
|
||||
}),
|
||||
...localQueryResultsView.getCommands(),
|
||||
...qhm.getCommands(),
|
||||
...variantAnalysisManager.getCommands(),
|
||||
@@ -877,12 +882,6 @@ async function activateWithInstalledDistribution(
|
||||
);
|
||||
}
|
||||
|
||||
registerQueryEditorCommands(ctx, {
|
||||
queryRunner: qs,
|
||||
cliServer,
|
||||
qhelpTmpDir: qhelpTmpDir.name,
|
||||
});
|
||||
|
||||
ctx.subscriptions.push(
|
||||
commandRunner("codeQL.copyVersion", async () => {
|
||||
const text = `CodeQL extension version: ${
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { commands, ExtensionContext, Uri, window } from "vscode";
|
||||
import { commands, Uri, window } from "vscode";
|
||||
import { CodeQLCliServer } from "./cli";
|
||||
import { QueryRunner } from "./queryRunner";
|
||||
import { commandRunner } from "./commandRunner";
|
||||
import { basename, join } from "path";
|
||||
import { getErrorMessage } from "./pure/helpers-pure";
|
||||
import { redactableError } from "./pure/errors";
|
||||
import { showAndLogExceptionWithTelemetry } from "./helpers";
|
||||
import { QueryEditorCommands } from "./common/commands";
|
||||
|
||||
type QueryEditorOptions = {
|
||||
queryRunner: QueryRunner;
|
||||
@@ -14,41 +14,23 @@ type QueryEditorOptions = {
|
||||
qhelpTmpDir: string;
|
||||
};
|
||||
|
||||
export function registerQueryEditorCommands(
|
||||
ctx: ExtensionContext,
|
||||
{ queryRunner, cliServer, qhelpTmpDir }: QueryEditorOptions,
|
||||
) {
|
||||
ctx.subscriptions.push(
|
||||
commandRunner("codeQL.openReferencedFile", async (selectedQuery: Uri) => {
|
||||
await openReferencedFile(queryRunner, cliServer, selectedQuery);
|
||||
}),
|
||||
);
|
||||
export function getQueryEditorCommands({
|
||||
queryRunner,
|
||||
cliServer,
|
||||
qhelpTmpDir,
|
||||
}: QueryEditorOptions): QueryEditorCommands {
|
||||
const openReferencedFileCommand = async (selectedQuery: Uri) =>
|
||||
await openReferencedFile(queryRunner, cliServer, selectedQuery);
|
||||
|
||||
// Since we are tracking extension usage through commands, this command mirrors the "codeQL.openReferencedFile" command
|
||||
ctx.subscriptions.push(
|
||||
commandRunner(
|
||||
"codeQL.openReferencedFileContextEditor",
|
||||
async (selectedQuery: Uri) => {
|
||||
await openReferencedFile(queryRunner, cliServer, selectedQuery);
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
// Since we are tracking extension usage through commands, this command mirrors the "codeQL.openReferencedFile" command
|
||||
ctx.subscriptions.push(
|
||||
commandRunner(
|
||||
"codeQL.openReferencedFileContextExplorer",
|
||||
async (selectedQuery: Uri) => {
|
||||
await openReferencedFile(queryRunner, cliServer, selectedQuery);
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
ctx.subscriptions.push(
|
||||
commandRunner("codeQL.previewQueryHelp", async (selectedQuery: Uri) => {
|
||||
await previewQueryHelp(cliServer, qhelpTmpDir, selectedQuery);
|
||||
}),
|
||||
);
|
||||
return {
|
||||
"codeQL.openReferencedFile": openReferencedFileCommand,
|
||||
// Since we are tracking extension usage through commands, this command mirrors the "codeQL.openReferencedFile" command
|
||||
"codeQL.openReferencedFileContextEditor": openReferencedFileCommand,
|
||||
// Since we are tracking extension usage through commands, this command mirrors the "codeQL.openReferencedFile" command
|
||||
"codeQL.openReferencedFileContextExplorer": openReferencedFileCommand,
|
||||
"codeQL.previewQueryHelp": async (selectedQuery: Uri) =>
|
||||
await previewQueryHelp(cliServer, qhelpTmpDir, selectedQuery),
|
||||
};
|
||||
}
|
||||
|
||||
async function previewQueryHelp(
|
||||
|
||||
Reference in New Issue
Block a user