Convert extensions/ql-vscode/src/mocks/vscode-mock-gh-api-server.ts to call typed commands

This commit is contained in:
Robert
2023-03-23 12:11:12 +00:00
parent 6b3a235a77
commit f84bf2dba0
2 changed files with 14 additions and 11 deletions

View File

@@ -879,7 +879,7 @@ async function activateWithInstalledDistribution(
const summaryLanguageSupport = new SummaryLanguageSupport(app);
ctx.subscriptions.push(summaryLanguageSupport);
const mockServer = new VSCodeMockGitHubApiServer(ctx);
const mockServer = new VSCodeMockGitHubApiServer(ctx, app);
ctx.subscriptions.push(mockServer);
void extLogger.log("Registering top-level command palette commands.");

View File

@@ -1,6 +1,5 @@
import { pathExists } from "fs-extra";
import {
commands,
env,
ExtensionContext,
ExtensionMode,
@@ -16,6 +15,7 @@ import {
import { DisposableObject } from "../pure/disposable-object";
import { MockGitHubApiServer } from "./mock-gh-api-server";
import { MockGitHubApiServerCommands } from "../common/commands";
import { App } from "../common/app";
/**
* "Interface" to the mock GitHub API server which implements VSCode interactions, such as
@@ -27,7 +27,10 @@ export class VSCodeMockGitHubApiServer extends DisposableObject {
private readonly server: MockGitHubApiServer;
private readonly config: MockGitHubApiConfigListener;
constructor(private readonly ctx: ExtensionContext) {
constructor(
private readonly ctx: ExtensionContext,
private readonly app: App,
) {
super();
this.server = new MockGitHubApiServer();
this.config = new MockGitHubApiConfigListener();
@@ -55,12 +58,12 @@ export class VSCodeMockGitHubApiServer extends DisposableObject {
public async stopServer(): Promise<void> {
this.server.stopServer();
await commands.executeCommand(
await this.app.commands.execute(
"setContext",
"codeQL.mockGitHubApiServer.scenarioLoaded",
false,
);
await commands.executeCommand(
await this.app.commands.execute(
"setContext",
"codeQL.mockGitHubApiServer.recording",
false,
@@ -92,7 +95,7 @@ export class VSCodeMockGitHubApiServer extends DisposableObject {
// Set a value in the context to track whether we have a scenario loaded.
// This allows us to use this to show/hide commands (see package.json)
await commands.executeCommand(
await this.app.commands.execute(
"setContext",
"codeQL.mockGitHubApiServer.scenarioLoaded",
true,
@@ -106,7 +109,7 @@ export class VSCodeMockGitHubApiServer extends DisposableObject {
await window.showInformationMessage("No scenario currently loaded");
} else {
await this.server.unloadScenario();
await commands.executeCommand(
await this.app.commands.execute(
"setContext",
"codeQL.mockGitHubApiServer.scenarioLoaded",
false,
@@ -125,7 +128,7 @@ export class VSCodeMockGitHubApiServer extends DisposableObject {
if (this.server.isScenarioLoaded) {
await this.server.unloadScenario();
await commands.executeCommand(
await this.app.commands.execute(
"setContext",
"codeQL.mockGitHubApiServer.scenarioLoaded",
false,
@@ -137,7 +140,7 @@ export class VSCodeMockGitHubApiServer extends DisposableObject {
await this.server.startRecording();
// Set a value in the context to track whether we are recording. This allows us to use this to show/hide commands (see package.json)
await commands.executeCommand(
await this.app.commands.execute(
"setContext",
"codeQL.mockGitHubApiServer.recording",
true,
@@ -155,7 +158,7 @@ export class VSCodeMockGitHubApiServer extends DisposableObject {
}
// Set a value in the context to track whether we are recording. This allows us to use this to show/hide commands (see package.json)
await commands.executeCommand(
await this.app.commands.execute(
"setContext",
"codeQL.mockGitHubApiServer.recording",
false,
@@ -210,7 +213,7 @@ export class VSCodeMockGitHubApiServer extends DisposableObject {
private async stopRecording(): Promise<void> {
// Set a value in the context to track whether we are recording. This allows us to use this to show/hide commands (see package.json)
await commands.executeCommand(
await this.app.commands.execute(
"setContext",
"codeQL.mockGitHubApiServer.recording",
false,