Convert mock API server commands to typed commands
This commit is contained in:
@@ -204,6 +204,14 @@ export type SummaryLanguageSupportCommands = {
|
||||
"codeQL.gotoQL": () => Promise<void>;
|
||||
};
|
||||
|
||||
export type MockGitHubApiServerCommands = {
|
||||
"codeQL.mockGitHubApiServer.startRecording": () => Promise<void>;
|
||||
"codeQL.mockGitHubApiServer.saveScenario": () => Promise<void>;
|
||||
"codeQL.mockGitHubApiServer.cancelRecording": () => Promise<void>;
|
||||
"codeQL.mockGitHubApiServer.loadScenario": () => Promise<void>;
|
||||
"codeQL.mockGitHubApiServer.unloadScenario": () => Promise<void>;
|
||||
};
|
||||
|
||||
export type AllCommands = BaseCommands &
|
||||
ResultsViewCommands &
|
||||
QueryHistoryCommands &
|
||||
@@ -214,7 +222,8 @@ export type AllCommands = BaseCommands &
|
||||
AstViewerCommands &
|
||||
PackagingCommands &
|
||||
EvalLogViewerCommands &
|
||||
SummaryLanguageSupportCommands;
|
||||
SummaryLanguageSupportCommands &
|
||||
MockGitHubApiServerCommands;
|
||||
|
||||
export type AppCommandManager = CommandManager<AllCommands>;
|
||||
|
||||
|
||||
@@ -822,6 +822,9 @@ async function activateWithInstalledDistribution(
|
||||
const summaryLanguageSupport = new SummaryLanguageSupport();
|
||||
ctx.subscriptions.push(summaryLanguageSupport);
|
||||
|
||||
const mockServer = new VSCodeMockGitHubApiServer(ctx);
|
||||
ctx.subscriptions.push(mockServer);
|
||||
|
||||
void extLogger.log("Registering top-level command palette commands.");
|
||||
|
||||
const allCommands: AllCommands = {
|
||||
@@ -847,6 +850,7 @@ async function activateWithInstalledDistribution(
|
||||
}),
|
||||
...evalLogViewer.getCommands(),
|
||||
...summaryLanguageSupport.getCommands(),
|
||||
...mockServer.getCommands(),
|
||||
};
|
||||
|
||||
for (const [commandName, command] of Object.entries(allCommands)) {
|
||||
@@ -973,39 +977,6 @@ async function activateWithInstalledDistribution(
|
||||
),
|
||||
);
|
||||
|
||||
const mockServer = new VSCodeMockGitHubApiServer(ctx);
|
||||
ctx.subscriptions.push(mockServer);
|
||||
ctx.subscriptions.push(
|
||||
commandRunner(
|
||||
"codeQL.mockGitHubApiServer.startRecording",
|
||||
async () => await mockServer.startRecording(),
|
||||
),
|
||||
);
|
||||
ctx.subscriptions.push(
|
||||
commandRunner(
|
||||
"codeQL.mockGitHubApiServer.saveScenario",
|
||||
async () => await mockServer.saveScenario(),
|
||||
),
|
||||
);
|
||||
ctx.subscriptions.push(
|
||||
commandRunner(
|
||||
"codeQL.mockGitHubApiServer.cancelRecording",
|
||||
async () => await mockServer.cancelRecording(),
|
||||
),
|
||||
);
|
||||
ctx.subscriptions.push(
|
||||
commandRunner(
|
||||
"codeQL.mockGitHubApiServer.loadScenario",
|
||||
async () => await mockServer.loadScenario(),
|
||||
),
|
||||
);
|
||||
ctx.subscriptions.push(
|
||||
commandRunner(
|
||||
"codeQL.mockGitHubApiServer.unloadScenario",
|
||||
async () => await mockServer.unloadScenario(),
|
||||
),
|
||||
);
|
||||
|
||||
await commands.executeCommand("codeQLDatabases.removeOrphanedDatabases");
|
||||
|
||||
void extLogger.log("Reading query history");
|
||||
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
} from "../config";
|
||||
import { DisposableObject } from "../pure/disposable-object";
|
||||
import { MockGitHubApiServer } from "./mock-gh-api-server";
|
||||
import { MockGitHubApiServerCommands } from "../common/commands";
|
||||
|
||||
/**
|
||||
* "Interface" to the mock GitHub API server which implements VSCode interactions, such as
|
||||
@@ -34,6 +35,19 @@ export class VSCodeMockGitHubApiServer extends DisposableObject {
|
||||
this.setupConfigListener();
|
||||
}
|
||||
|
||||
public getCommands(): MockGitHubApiServerCommands {
|
||||
return {
|
||||
"codeQL.mockGitHubApiServer.startRecording":
|
||||
this.startRecording.bind(this),
|
||||
"codeQL.mockGitHubApiServer.saveScenario": this.saveScenario.bind(this),
|
||||
"codeQL.mockGitHubApiServer.cancelRecording":
|
||||
this.cancelRecording.bind(this),
|
||||
"codeQL.mockGitHubApiServer.loadScenario": this.loadScenario.bind(this),
|
||||
"codeQL.mockGitHubApiServer.unloadScenario":
|
||||
this.unloadScenario.bind(this),
|
||||
};
|
||||
}
|
||||
|
||||
public async startServer(): Promise<void> {
|
||||
this.server.startServer();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user