Skip to content

Commit 5303ec6

Browse files
committed
Name updates.
1 parent 52b00fe commit 5303ec6

13 files changed

Lines changed: 65 additions & 59 deletions

File tree

extensions/ql-vscode/src/common/app.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Disposable } from "../pure/disposable-object";
33
import { AppEventEmitter } from "./events";
44
import { Logger } from "./logging";
55
import { Memento } from "./memento";
6-
import { ExtensionCommandManager } from "./commands";
6+
import { AppCommandManager } from "./commands";
77

88
export interface App {
99
createEventEmitter<T>(): AppEventEmitter<T>;
@@ -16,7 +16,7 @@ export interface App {
1616
readonly workspaceStoragePath?: string;
1717
readonly workspaceState: Memento;
1818
readonly credentials: Credentials;
19-
readonly commandManager: ExtensionCommandManager;
19+
readonly commands: AppCommandManager;
2020
}
2121

2222
export enum AppMode {

extensions/ql-vscode/src/common/commands.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import { CommandManager } from "../packages/commands";
77
* the implementation in the corresponding `getCommands` function.
88
*/
99

10-
// Commands directly in the extension
11-
export type ExtensionCommands = {
10+
// Base commands not tied directly to a module like e.g. variant analysis.
11+
export type BaseCommands = {
1212
"codeQL.openDocumentation": () => Promise<void>;
1313
};
1414

@@ -19,6 +19,6 @@ export type VariantAnalysisCommands = {
1919
) => Promise<void>;
2020
};
2121

22-
export type AllCommands = ExtensionCommands & VariantAnalysisCommands;
22+
export type AllCommands = BaseCommands & VariantAnalysisCommands;
2323

24-
export type ExtensionCommandManager = CommandManager<AllCommands>;
24+
export type AppCommandManager = CommandManager<AllCommands>;

extensions/ql-vscode/src/common/vscode/commands.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,23 @@ import { commandRunner } from "../../commandRunner";
33
import { CommandFunction, CommandManager } from "../../packages/commands";
44

55
/**
6-
* Intializes a command manager for VSCode, wrapping the commandRunner
6+
* Create a command manager for VSCode, wrapping the commandRunner
77
* and vscode.executeCommand.
88
*/
9-
export function initializeVSCodeCommandManager<
9+
export function createVSCodeCommandManager<
1010
Commands extends Record<string, CommandFunction>,
1111
>(): CommandManager<Commands> {
12-
return new CommandManager(commandRunner, wrappedExecuteCommand);
12+
return new CommandManager(commandRunner, wrapExecuteCommand);
1313
}
1414

15-
async function wrappedExecuteCommand<
15+
/**
16+
* wrapExecuteCommand wraps commands.executeCommand to satisfy that the
17+
* type is a Promise. Type script does not seem to be smart enough
18+
* to figure out that `ReturnType<Commands[CommandName]>` is actually
19+
* a Promise, so we need to add a second layer of wrapping and unwrapping
20+
* (The `Promise<Awaited<` part) to get the right types.
21+
*/
22+
async function wrapExecuteCommand<
1623
Commands extends Record<string, CommandFunction>,
1724
CommandName extends keyof Commands & string = keyof Commands & string,
1825
>(

extensions/ql-vscode/src/common/vscode/vscode-app.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ import { AppEventEmitter } from "../events";
66
import { extLogger, Logger } from "../logging";
77
import { Memento } from "../memento";
88
import { VSCodeAppEventEmitter } from "./events";
9-
import { ExtensionCommandManager } from "../commands";
10-
import { initializeVSCodeCommandManager } from "./commands";
9+
import { AppCommandManager } from "../commands";
10+
import { createVSCodeCommandManager } from "./commands";
1111

1212
export class ExtensionApp implements App {
1313
public readonly credentials: VSCodeCredentials;
14-
public readonly commandManager: ExtensionCommandManager;
14+
public readonly commands: AppCommandManager;
1515

1616
public constructor(
1717
public readonly extensionContext: vscode.ExtensionContext,
1818
) {
1919
this.credentials = new VSCodeCredentials();
20-
this.commandManager = initializeVSCodeCommandManager();
21-
extensionContext.subscriptions.push(this.commandManager);
20+
this.commands = createVSCodeCommandManager();
21+
extensionContext.subscriptions.push(this.commands);
2222
}
2323

2424
public get extensionPath(): string {

extensions/ql-vscode/src/extension.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ import { RepositoriesFilterSortStateWithIds } from "./pure/variant-analysis-filt
136136
import { DbModule } from "./databases/db-module";
137137
import { redactableError } from "./pure/errors";
138138
import { QueryHistoryDirs } from "./query-history/query-history-dirs";
139-
import { AllCommands, ExtensionCommands } from "./common/commands";
139+
import { AllCommands, BaseCommands } from "./common/commands";
140140

141141
/**
142142
* extension.ts
@@ -168,7 +168,10 @@ let isInstallingOrUpdatingDistribution = false;
168168
const extensionId = "GitHub.vscode-codeql";
169169
const extension = extensions.getExtension(extensionId);
170170

171-
function getCommands(): ExtensionCommands {
171+
/**
172+
* Return all commands that are not tied to the more specific managers.
173+
*/
174+
function getCommands(): BaseCommands {
172175
return {
173176
"codeQL.openDocumentation": async () => {
174177
await env.openExternal(Uri.parse("https://codeql.github.com/docs/"));
@@ -1206,10 +1209,7 @@ async function activateWithInstalledDistribution(
12061209
};
12071210

12081211
for (const [commandName, command] of Object.entries(allCommands)) {
1209-
app.commandManager.registerCommand(
1210-
commandName as keyof AllCommands,
1211-
command,
1212-
);
1212+
app.commands.register(commandName as keyof AllCommands, command);
12131213
}
12141214

12151215
ctx.subscriptions.push(

extensions/ql-vscode/src/packages/commands/CommandManager.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
* and then allow other parts to call those commands in a well-typed manner.
66
*/
77

8-
export interface Disposable {
9-
dispose(): void;
10-
}
8+
import { Disposable } from "./Disposable";
119

1210
/**
1311
* A command function is a completely untyped command.
@@ -32,7 +30,7 @@ export class CommandManager<
3230
constructor(
3331
private readonly commandRegister: <T extends CommandName>(
3432
commandName: T,
35-
definition: Commands[T],
33+
fn: Commands[T],
3634
) => Disposable,
3735
private readonly commandExecute: <T extends CommandName>(
3836
commandName: T,
@@ -43,7 +41,7 @@ export class CommandManager<
4341
/**
4442
* Register a command with the specified name and implementation.
4543
*/
46-
registerCommand<T extends CommandName>(
44+
register<T extends CommandName>(
4745
commandName: T,
4846
definition: Commands[T],
4947
): void {
@@ -53,7 +51,7 @@ export class CommandManager<
5351
/**
5452
* Execute a command with the specified name and the provided arguments.
5553
*/
56-
executeCommand<T extends CommandName>(
54+
execute<T extends CommandName>(
5755
commandName: T,
5856
...args: Parameters<Commands[T]>
5957
): Promise<Awaited<ReturnType<Commands[T]>>> {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* This interface mirrors the vscode.Disaposable class, so that
3+
* the command manager does not depend on vscode directly.
4+
*/
5+
export interface Disposable {
6+
dispose(): void;
7+
}

extensions/ql-vscode/src/variant-analysis/variant-analysis-manager.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,7 @@ import { URLSearchParams } from "url";
6262
import { DbManager } from "../databases/db-manager";
6363
import { App } from "../common/app";
6464
import { redactableError } from "../pure/errors";
65-
import {
66-
ExtensionCommandManager,
67-
VariantAnalysisCommands,
68-
} from "../common/commands";
65+
import { AppCommandManager, VariantAnalysisCommands } from "../common/commands";
6966

7067
export class VariantAnalysisManager
7168
extends DisposableObject
@@ -135,8 +132,8 @@ export class VariantAnalysisManager
135132
};
136133
}
137134

138-
get commandManager(): ExtensionCommandManager {
139-
return this.app.commandManager;
135+
get commandManager(): AppCommandManager {
136+
return this.app.commands;
140137
}
141138

142139
public async runVariantAnalysis(

extensions/ql-vscode/src/variant-analysis/variant-analysis-view-manager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {
22
VariantAnalysis,
33
VariantAnalysisScannedRepositoryState,
44
} from "./shared/variant-analysis";
5-
import { ExtensionCommandManager } from "../common/commands";
5+
import { AppCommandManager } from "../common/commands";
66

77
export interface VariantAnalysisViewInterface {
88
variantAnalysisId: number;
@@ -12,7 +12,7 @@ export interface VariantAnalysisViewInterface {
1212
export interface VariantAnalysisViewManager<
1313
T extends VariantAnalysisViewInterface,
1414
> {
15-
commandManager: ExtensionCommandManager;
15+
commandManager: AppCommandManager;
1616

1717
registerView(view: T): void;
1818
unregisterView(view: T): void;

extensions/ql-vscode/src/variant-analysis/variant-analysis-view.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export class VariantAnalysisView
145145
);
146146
break;
147147
case "openLogs":
148-
await this.manager.commandManager.executeCommand(
148+
await this.manager.commandManager.execute(
149149
"codeQL.openVariantAnalysisLogs",
150150
this.variantAnalysisId,
151151
);

0 commit comments

Comments
 (0)