Merge pull request #2208 from github/koesie10/mock-server-typed-commands

Convert mock API server commands to typed commands
This commit is contained in:
Koen Vlaswinkel
2023-03-22 16:28:28 +01:00
committed by GitHub
3 changed files with 28 additions and 34 deletions

View File

@@ -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>;

View File

@@ -823,6 +823,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 = {
@@ -848,6 +851,7 @@ async function activateWithInstalledDistribution(
}),
...evalLogViewer.getCommands(),
...summaryLanguageSupport.getCommands(),
...mockServer.getCommands(),
};
for (const [commandName, command] of Object.entries(allCommands)) {
@@ -974,39 +978,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");

View File

@@ -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();
}