Skip to content

Commit fd7013f

Browse files
committed
Convert mock API server commands to typed commands
1 parent b2fceb9 commit fd7013f

File tree

3 files changed

+28
-34
lines changed

3 files changed

+28
-34
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,14 @@ export type SummaryLanguageSupportCommands = {
204204
"codeQL.gotoQL": () => Promise<void>;
205205
};
206206

207+
export type MockGitHubApiServerCommands = {
208+
"codeQL.mockGitHubApiServer.startRecording": () => Promise<void>;
209+
"codeQL.mockGitHubApiServer.saveScenario": () => Promise<void>;
210+
"codeQL.mockGitHubApiServer.cancelRecording": () => Promise<void>;
211+
"codeQL.mockGitHubApiServer.loadScenario": () => Promise<void>;
212+
"codeQL.mockGitHubApiServer.unloadScenario": () => Promise<void>;
213+
};
214+
207215
export type AllCommands = BaseCommands &
208216
ResultsViewCommands &
209217
QueryHistoryCommands &
@@ -214,7 +222,8 @@ export type AllCommands = BaseCommands &
214222
AstViewerCommands &
215223
PackagingCommands &
216224
EvalLogViewerCommands &
217-
SummaryLanguageSupportCommands;
225+
SummaryLanguageSupportCommands &
226+
MockGitHubApiServerCommands;
218227

219228
export type AppCommandManager = CommandManager<AllCommands>;
220229

extensions/ql-vscode/src/extension.ts

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,9 @@ async function activateWithInstalledDistribution(
822822
const summaryLanguageSupport = new SummaryLanguageSupport();
823823
ctx.subscriptions.push(summaryLanguageSupport);
824824

825+
const mockServer = new VSCodeMockGitHubApiServer(ctx);
826+
ctx.subscriptions.push(mockServer);
827+
825828
void extLogger.log("Registering top-level command palette commands.");
826829

827830
const allCommands: AllCommands = {
@@ -847,6 +850,7 @@ async function activateWithInstalledDistribution(
847850
}),
848851
...evalLogViewer.getCommands(),
849852
...summaryLanguageSupport.getCommands(),
853+
...mockServer.getCommands(),
850854
};
851855

852856
for (const [commandName, command] of Object.entries(allCommands)) {
@@ -973,39 +977,6 @@ async function activateWithInstalledDistribution(
973977
),
974978
);
975979

976-
const mockServer = new VSCodeMockGitHubApiServer(ctx);
977-
ctx.subscriptions.push(mockServer);
978-
ctx.subscriptions.push(
979-
commandRunner(
980-
"codeQL.mockGitHubApiServer.startRecording",
981-
async () => await mockServer.startRecording(),
982-
),
983-
);
984-
ctx.subscriptions.push(
985-
commandRunner(
986-
"codeQL.mockGitHubApiServer.saveScenario",
987-
async () => await mockServer.saveScenario(),
988-
),
989-
);
990-
ctx.subscriptions.push(
991-
commandRunner(
992-
"codeQL.mockGitHubApiServer.cancelRecording",
993-
async () => await mockServer.cancelRecording(),
994-
),
995-
);
996-
ctx.subscriptions.push(
997-
commandRunner(
998-
"codeQL.mockGitHubApiServer.loadScenario",
999-
async () => await mockServer.loadScenario(),
1000-
),
1001-
);
1002-
ctx.subscriptions.push(
1003-
commandRunner(
1004-
"codeQL.mockGitHubApiServer.unloadScenario",
1005-
async () => await mockServer.unloadScenario(),
1006-
),
1007-
);
1008-
1009980
await commands.executeCommand("codeQLDatabases.removeOrphanedDatabases");
1010981

1011982
void extLogger.log("Reading query history");

extensions/ql-vscode/src/mocks/vscode-mock-gh-api-server.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
} from "../config";
1616
import { DisposableObject } from "../pure/disposable-object";
1717
import { MockGitHubApiServer } from "./mock-gh-api-server";
18+
import { MockGitHubApiServerCommands } from "../common/commands";
1819

1920
/**
2021
* "Interface" to the mock GitHub API server which implements VSCode interactions, such as
@@ -34,6 +35,19 @@ export class VSCodeMockGitHubApiServer extends DisposableObject {
3435
this.setupConfigListener();
3536
}
3637

38+
public getCommands(): MockGitHubApiServerCommands {
39+
return {
40+
"codeQL.mockGitHubApiServer.startRecording":
41+
this.startRecording.bind(this),
42+
"codeQL.mockGitHubApiServer.saveScenario": this.saveScenario.bind(this),
43+
"codeQL.mockGitHubApiServer.cancelRecording":
44+
this.cancelRecording.bind(this),
45+
"codeQL.mockGitHubApiServer.loadScenario": this.loadScenario.bind(this),
46+
"codeQL.mockGitHubApiServer.unloadScenario":
47+
this.unloadScenario.bind(this),
48+
};
49+
}
50+
3751
public async startServer(): Promise<void> {
3852
this.server.startServer();
3953
}

0 commit comments

Comments
 (0)