Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion extensions/ql-vscode/src/common/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 &
Expand All @@ -214,7 +222,8 @@ export type AllCommands = BaseCommands &
AstViewerCommands &
PackagingCommands &
EvalLogViewerCommands &
SummaryLanguageSupportCommands;
SummaryLanguageSupportCommands &
MockGitHubApiServerCommands;

export type AppCommandManager = CommandManager<AllCommands>;

Expand Down
37 changes: 4 additions & 33 deletions extensions/ql-vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -847,6 +850,7 @@ async function activateWithInstalledDistribution(
}),
...evalLogViewer.getCommands(),
...summaryLanguageSupport.getCommands(),
...mockServer.getCommands(),
};

for (const [commandName, command] of Object.entries(allCommands)) {
Expand Down Expand Up @@ -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");
Expand Down
14 changes: 14 additions & 0 deletions extensions/ql-vscode/src/mocks/vscode-mock-gh-api-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
}
Expand Down