Expose QueryServerCommandManager from app

This commit is contained in:
Robert
2023-06-21 15:33:23 +01:00
committed by Nora
parent 3f1b619904
commit f25d7baa56
5 changed files with 16 additions and 9 deletions

View File

@@ -3,7 +3,7 @@ import { Disposable } from "./disposable-object";
import { AppEventEmitter } from "./events"; import { AppEventEmitter } from "./events";
import { NotificationLogger } from "./logging"; import { NotificationLogger } from "./logging";
import { Memento } from "./memento"; import { Memento } from "./memento";
import { AppCommandManager } from "./commands"; import { AppCommandManager, QueryServerCommandManager } from "./commands";
import { AppTelemetry } from "./telemetry"; import { AppTelemetry } from "./telemetry";
export interface App { export interface App {
@@ -18,6 +18,7 @@ export interface App {
readonly workspaceState: Memento; readonly workspaceState: Memento;
readonly credentials: Credentials; readonly credentials: Credentials;
readonly commands: AppCommandManager; readonly commands: AppCommandManager;
readonly queryServerCommands: QueryServerCommandManager;
readonly environment: EnvironmentContext; readonly environment: EnvironmentContext;
} }

View File

@@ -353,8 +353,7 @@ export type AllExtensionCommands = BaseCommands &
export type AllCommands = AllExtensionCommands & export type AllCommands = AllExtensionCommands &
PreActivationCommands & PreActivationCommands &
BuiltInVsCodeCommands & BuiltInVsCodeCommands;
QueryServerCommands;
export type AppCommandManager = CommandManager<AllCommands>; export type AppCommandManager = CommandManager<AllCommands>;

View File

@@ -30,7 +30,7 @@ export class QueriesPanel extends DisposableObject {
private async runLocalQuery( private async runLocalQuery(
queryTreeViewItem: QueryTreeViewItem, queryTreeViewItem: QueryTreeViewItem,
): Promise<void> { ): Promise<void> {
await this.app.commands.execute( await this.app.queryServerCommands.execute(
"codeQL.runLocalQueryFromQueriesPanel", "codeQL.runLocalQueryFromQueriesPanel",
vscode.Uri.parse(queryTreeViewItem.path), vscode.Uri.parse(queryTreeViewItem.path),
); );

View File

@@ -6,7 +6,10 @@ import { createMockLogger } from "./loggerMock";
import { createMockMemento } from "../mock-memento"; import { createMockMemento } from "../mock-memento";
import { testCredentialsWithStub } from "../factories/authentication"; import { testCredentialsWithStub } from "../factories/authentication";
import { Credentials } from "../../src/common/authentication"; import { Credentials } from "../../src/common/authentication";
import { AppCommandManager } from "../../src/common/commands"; import {
AppCommandManager,
QueryServerCommandManager,
} from "../../src/common/commands";
import { createMockCommandManager } from "./commandsMock"; import { createMockCommandManager } from "./commandsMock";
import { NotificationLogger } from "../../src/common/logging"; import { NotificationLogger } from "../../src/common/logging";
import { AppTelemetry } from "../../src/common/telemetry"; import { AppTelemetry } from "../../src/common/telemetry";
@@ -20,6 +23,7 @@ export function createMockApp({
workspaceState = createMockMemento(), workspaceState = createMockMemento(),
credentials = testCredentialsWithStub(), credentials = testCredentialsWithStub(),
commands = createMockCommandManager(), commands = createMockCommandManager(),
queryServerCommands = createMockCommandManager(),
environment = createMockEnvironmentContext(), environment = createMockEnvironmentContext(),
logger = createMockLogger(), logger = createMockLogger(),
telemetry = createMockTelemetryReporter(), telemetry = createMockTelemetryReporter(),
@@ -31,6 +35,7 @@ export function createMockApp({
workspaceState?: Memento; workspaceState?: Memento;
credentials?: Credentials; credentials?: Credentials;
commands?: AppCommandManager; commands?: AppCommandManager;
queryServerCommands?: QueryServerCommandManager;
environment?: EnvironmentContext; environment?: EnvironmentContext;
logger?: NotificationLogger; logger?: NotificationLogger;
telemetry?: AppTelemetry; telemetry?: AppTelemetry;
@@ -47,6 +52,7 @@ export function createMockApp({
createEventEmitter, createEventEmitter,
credentials, credentials,
commands, commands,
queryServerCommands,
environment, environment,
}; };
} }

View File

@@ -1,13 +1,14 @@
import { AppCommandManager } from "../../src/common/commands";
import { CommandFunction, CommandManager } from "../../src/packages/commands"; import { CommandFunction, CommandManager } from "../../src/packages/commands";
import { Disposable } from "../../src/packages/commands/Disposable"; import { Disposable } from "../../src/packages/commands/Disposable";
export function createMockCommandManager({ export function createMockCommandManager<
Commands extends Record<string, CommandFunction>,
>({
registerCommand = jest.fn(), registerCommand = jest.fn(),
executeCommand = jest.fn(), executeCommand = jest.fn(),
}: { }: {
registerCommand?: (commandName: string, fn: CommandFunction) => Disposable; registerCommand?: (commandName: string, fn: CommandFunction) => Disposable;
executeCommand?: (commandName: string, ...args: any[]) => Promise<any>; executeCommand?: (commandName: string, ...args: any[]) => Promise<any>;
} = {}): AppCommandManager { } = {}): CommandManager<Commands> {
return new CommandManager(registerCommand, executeCommand); return new CommandManager<Commands>(registerCommand, executeCommand);
} }