Skip to content

Commit be3459c

Browse files
committed
Convert query editing commands to typed commands
1 parent 5ac5de8 commit be3459c

File tree

3 files changed

+37
-43
lines changed

3 files changed

+37
-43
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@ export type BaseCommands = {
3838
"codeQL.restartQueryServer": () => Promise<void>;
3939
};
4040

41+
// Commands used when working with queries in the editor
42+
export type QueryEditorCommands = {
43+
"codeQL.openReferencedFile": (selectedQuery: Uri) => Promise<void>;
44+
"codeQL.openReferencedFileContextEditor": (
45+
selectedQuery: Uri,
46+
) => Promise<void>;
47+
"codeQL.openReferencedFileContextExplorer": (
48+
selectedQuery: Uri,
49+
) => Promise<void>;
50+
"codeQL.previewQueryHelp": (selectedQuery: Uri) => Promise<void>;
51+
};
52+
4153
// Commands used for running local queries
4254
export type LocalQueryCommands = {
4355
"codeQL.runQuery": (uri?: Uri) => Promise<void>;
@@ -213,6 +225,7 @@ export type MockGitHubApiServerCommands = {
213225
};
214226

215227
export type AllCommands = BaseCommands &
228+
QueryEditorCommands &
216229
ResultsViewCommands &
217230
QueryHistoryCommands &
218231
LocalDatabasesCommands &

extensions/ql-vscode/src/extension.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ import {
120120
showResultsForCompletedQuery,
121121
} from "./local-queries";
122122
import { getAstCfgCommands } from "./ast-cfg-commands";
123-
import { registerQueryEditorCommands } from "./query-editor";
123+
import { getQueryEditorCommands } from "./query-editor";
124124

125125
/**
126126
* extension.ts
@@ -829,6 +829,11 @@ async function activateWithInstalledDistribution(
829829

830830
const allCommands: AllCommands = {
831831
...getCommands(cliServer, qs),
832+
...getQueryEditorCommands({
833+
queryRunner: qs,
834+
cliServer,
835+
qhelpTmpDir: qhelpTmpDir.name,
836+
}),
832837
...localQueryResultsView.getCommands(),
833838
...qhm.getCommands(),
834839
...variantAnalysisManager.getCommands(),
@@ -877,12 +882,6 @@ async function activateWithInstalledDistribution(
877882
);
878883
}
879884

880-
registerQueryEditorCommands(ctx, {
881-
queryRunner: qs,
882-
cliServer,
883-
qhelpTmpDir: qhelpTmpDir.name,
884-
});
885-
886885
ctx.subscriptions.push(
887886
commandRunner("codeQL.copyVersion", async () => {
888887
const text = `CodeQL extension version: ${

extensions/ql-vscode/src/query-editor.ts

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { commands, ExtensionContext, Uri, window } from "vscode";
1+
import { commands, Uri, window } from "vscode";
22
import { CodeQLCliServer } from "./cli";
33
import { QueryRunner } from "./queryRunner";
4-
import { commandRunner } from "./commandRunner";
54
import { basename, join } from "path";
65
import { getErrorMessage } from "./pure/helpers-pure";
76
import { redactableError } from "./pure/errors";
87
import { showAndLogExceptionWithTelemetry } from "./helpers";
8+
import { QueryEditorCommands } from "./common/commands";
99

1010
type QueryEditorOptions = {
1111
queryRunner: QueryRunner;
@@ -14,41 +14,23 @@ type QueryEditorOptions = {
1414
qhelpTmpDir: string;
1515
};
1616

17-
export function registerQueryEditorCommands(
18-
ctx: ExtensionContext,
19-
{ queryRunner, cliServer, qhelpTmpDir }: QueryEditorOptions,
20-
) {
21-
ctx.subscriptions.push(
22-
commandRunner("codeQL.openReferencedFile", async (selectedQuery: Uri) => {
23-
await openReferencedFile(queryRunner, cliServer, selectedQuery);
24-
}),
25-
);
17+
export function getQueryEditorCommands({
18+
queryRunner,
19+
cliServer,
20+
qhelpTmpDir,
21+
}: QueryEditorOptions): QueryEditorCommands {
22+
const openReferencedFileCommand = async (selectedQuery: Uri) =>
23+
await openReferencedFile(queryRunner, cliServer, selectedQuery);
2624

27-
// Since we are tracking extension usage through commands, this command mirrors the "codeQL.openReferencedFile" command
28-
ctx.subscriptions.push(
29-
commandRunner(
30-
"codeQL.openReferencedFileContextEditor",
31-
async (selectedQuery: Uri) => {
32-
await openReferencedFile(queryRunner, cliServer, selectedQuery);
33-
},
34-
),
35-
);
36-
37-
// Since we are tracking extension usage through commands, this command mirrors the "codeQL.openReferencedFile" command
38-
ctx.subscriptions.push(
39-
commandRunner(
40-
"codeQL.openReferencedFileContextExplorer",
41-
async (selectedQuery: Uri) => {
42-
await openReferencedFile(queryRunner, cliServer, selectedQuery);
43-
},
44-
),
45-
);
46-
47-
ctx.subscriptions.push(
48-
commandRunner("codeQL.previewQueryHelp", async (selectedQuery: Uri) => {
49-
await previewQueryHelp(cliServer, qhelpTmpDir, selectedQuery);
50-
}),
51-
);
25+
return {
26+
"codeQL.openReferencedFile": openReferencedFileCommand,
27+
// Since we are tracking extension usage through commands, this command mirrors the "codeQL.openReferencedFile" command
28+
"codeQL.openReferencedFileContextEditor": openReferencedFileCommand,
29+
// Since we are tracking extension usage through commands, this command mirrors the "codeQL.openReferencedFile" command
30+
"codeQL.openReferencedFileContextExplorer": openReferencedFileCommand,
31+
"codeQL.previewQueryHelp": async (selectedQuery: Uri) =>
32+
await previewQueryHelp(cliServer, qhelpTmpDir, selectedQuery),
33+
};
5234
}
5335

5436
async function previewQueryHelp(

0 commit comments

Comments
 (0)