Skip to content

Commit 61974a7

Browse files
committed
Register concrete command from extension.
1 parent d87911a commit 61974a7

3 files changed

Lines changed: 57 additions & 2 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { commands } from "vscode";
2+
import { commandRunner } from "./commandRunner";
3+
import { CommandFunction, CommandManager } from "./packages/commands";
4+
5+
export function initializeVSCodeCommandManager<
6+
Commands extends Record<string, CommandFunction>,
7+
>(): CommandManager<Commands> {
8+
return new CommandManager(commandRunner, wrappedExecuteCommand);
9+
}
10+
11+
async function wrappedExecuteCommand<
12+
Commands extends Record<string, CommandFunction>,
13+
CommandName extends keyof Commands & string = keyof Commands & string,
14+
>(
15+
commandName: CommandName,
16+
...args: Parameters<Commands[CommandName]>
17+
): Promise<Awaited<ReturnType<Commands[CommandName]>>> {
18+
return await commands.executeCommand<
19+
Awaited<ReturnType<Commands[CommandName]>>
20+
>(commandName, ...args);
21+
}
22+
23+
export type ExtensionCommands = {
24+
"codeQL.openVariantAnalysisLogs": (
25+
variantAnalysisId: number,
26+
) => Promise<void>;
27+
};
28+
export type AllCommands = ExtensionCommands;

extensions/ql-vscode/src/extension.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ import { RepositoriesFilterSortStateWithIds } from "./pure/variant-analysis-filt
137137
import { DbModule } from "./databases/db-module";
138138
import { redactableError } from "./pure/errors";
139139
import { QueryHistoryDirs } from "./query-history/query-history-dirs";
140+
import {
141+
AllCommands,
142+
ExtensionCommands,
143+
initializeVSCodeCommandManager,
144+
} from "./commands";
140145

141146
/**
142147
* extension.ts
@@ -168,6 +173,16 @@ let isInstallingOrUpdatingDistribution = false;
168173
const extensionId = "GitHub.vscode-codeql";
169174
const extension = extensions.getExtension(extensionId);
170175

176+
function getCommands(
177+
variantAnalysisManager: VariantAnalysisManager,
178+
): ExtensionCommands {
179+
return {
180+
"codeQL.openVariantAnalysisLogs": async (variantAnalysisId: number) => {
181+
await variantAnalysisManager.openVariantAnalysisLogs(variantAnalysisId);
182+
},
183+
};
184+
}
185+
171186
/**
172187
* If the user tries to execute vscode commands after extension activation is failed, give
173188
* a sensible error message.
@@ -1153,6 +1168,7 @@ async function activateWithInstalledDistribution(
11531168
),
11541169
);
11551170

1171+
/*
11561172
ctx.subscriptions.push(
11571173
commandRunner(
11581174
"codeQL.openVariantAnalysisLogs",
@@ -1161,6 +1177,17 @@ async function activateWithInstalledDistribution(
11611177
},
11621178
),
11631179
);
1180+
*/
1181+
1182+
const vsCommandRunner = initializeVSCodeCommandManager<AllCommands>();
1183+
ctx.subscriptions.push(vsCommandRunner);
1184+
const allCommands: Partial<AllCommands> = {
1185+
...getCommands(variantAnalysisManager),
1186+
};
1187+
1188+
for (const [commandName, command] of Object.entries(allCommands)) {
1189+
vsCommandRunner.registerCommand(commandName as keyof AllCommands, command);
1190+
}
11641191

11651192
ctx.subscriptions.push(
11661193
commandRunner(

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class CommandManager<
2121
private readonly commandExecute: <T extends CommandName>(
2222
commandName: T,
2323
...args: Parameters<Commands[T]>
24-
) => Promise<ReturnType<Commands[T]>>,
24+
) => Promise<Awaited<ReturnType<Commands[T]>>>,
2525
) {}
2626

2727
registerCommand<T extends CommandName>(
@@ -34,7 +34,7 @@ export class CommandManager<
3434
executeCommand<T extends CommandName>(
3535
commandName: T,
3636
...args: Parameters<Commands[T]>
37-
): Promise<ReturnType<Commands[T]>> {
37+
): Promise<Awaited<ReturnType<Commands[T]>>> {
3838
return this.commandExecute(commandName, ...args);
3939
}
4040

0 commit comments

Comments
 (0)