Skip to content

Commit 20f85f2

Browse files
authored
Merge pull request #2210 from github/koesie10/base-typed-commands
Convert some base commands to typed commands
2 parents 297fa2e + a27ca2e commit 20f85f2

File tree

2 files changed

+35
-39
lines changed

2 files changed

+35
-39
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ export type BuiltInVsCodeCommands = {
4242
// Base commands not tied directly to a module like e.g. variant analysis.
4343
export type BaseCommands = {
4444
"codeQL.openDocumentation": () => Promise<void>;
45+
"codeQL.showLogs": () => Promise<void>;
46+
"codeQL.authenticateToGitHub": () => Promise<void>;
4547

48+
"codeQL.copyVersion": () => Promise<void>;
4649
"codeQL.restartQueryServer": () => Promise<void>;
4750
};
4851

extensions/ql-vscode/src/extension.ts

Lines changed: 32 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ import {
121121
} from "./local-queries";
122122
import { getAstCfgCommands } from "./ast-cfg-commands";
123123
import { getQueryEditorCommands } from "./query-editor";
124+
import { App } from "./common/app";
124125

125126
/**
126127
* extension.ts
@@ -156,9 +157,18 @@ const extension = extensions.getExtension(extensionId);
156157
* Return all commands that are not tied to the more specific managers.
157158
*/
158159
function getCommands(
160+
app: App,
159161
cliServer: CodeQLCliServer,
160162
queryRunner: QueryRunner,
161163
): BaseCommands {
164+
const getCliVersion = async () => {
165+
try {
166+
return await cliServer.getVersion();
167+
} catch {
168+
return "<missing>";
169+
}
170+
};
171+
162172
return {
163173
"codeQL.openDocumentation": async () => {
164174
await env.openExternal(Uri.parse("https://codeql.github.com/docs/"));
@@ -177,6 +187,27 @@ function getCommands(
177187
title: "Restarting Query Server",
178188
},
179189
),
190+
"codeQL.copyVersion": async () => {
191+
const text = `CodeQL extension version: ${
192+
extension?.packageJSON.version
193+
} \nCodeQL CLI version: ${await getCliVersion()} \nPlatform: ${platform()} ${arch()}`;
194+
await env.clipboard.writeText(text);
195+
void showAndLogInformationMessage(text);
196+
},
197+
"codeQL.authenticateToGitHub": async () => {
198+
/**
199+
* Credentials for authenticating to GitHub.
200+
* These are used when making API calls.
201+
*/
202+
const octokit = await app.credentials.getOctokit();
203+
const userInfo = await octokit.users.getAuthenticated();
204+
void showAndLogInformationMessage(
205+
`Authenticated to GitHub as user: ${userInfo.data.login}`,
206+
);
207+
},
208+
"codeQL.showLogs": async () => {
209+
extLogger.show();
210+
},
180211
};
181212
}
182213

@@ -841,7 +872,7 @@ async function activateWithInstalledDistribution(
841872
void extLogger.log("Registering top-level command palette commands.");
842873

843874
const allCommands: AllExtensionCommands = {
844-
...getCommands(cliServer, qs),
875+
...getCommands(app, cliServer, qs),
845876
...getQueryEditorCommands({
846877
queryRunner: qs,
847878
cliServer,
@@ -896,44 +927,6 @@ async function activateWithInstalledDistribution(
896927
);
897928
}
898929

899-
ctx.subscriptions.push(
900-
commandRunner("codeQL.copyVersion", async () => {
901-
const text = `CodeQL extension version: ${
902-
extension?.packageJSON.version
903-
} \nCodeQL CLI version: ${await getCliVersion()} \nPlatform: ${platform()} ${arch()}`;
904-
await env.clipboard.writeText(text);
905-
void showAndLogInformationMessage(text);
906-
}),
907-
);
908-
909-
const getCliVersion = async () => {
910-
try {
911-
return await cliServer.getVersion();
912-
} catch {
913-
return "<missing>";
914-
}
915-
};
916-
917-
ctx.subscriptions.push(
918-
commandRunner("codeQL.authenticateToGitHub", async () => {
919-
/**
920-
* Credentials for authenticating to GitHub.
921-
* These are used when making API calls.
922-
*/
923-
const octokit = await app.credentials.getOctokit();
924-
const userInfo = await octokit.users.getAuthenticated();
925-
void showAndLogInformationMessage(
926-
`Authenticated to GitHub as user: ${userInfo.data.login}`,
927-
);
928-
}),
929-
);
930-
931-
ctx.subscriptions.push(
932-
commandRunner("codeQL.showLogs", async () => {
933-
extLogger.show();
934-
}),
935-
);
936-
937930
void extLogger.log("Starting language server.");
938931
await client.start();
939932
ctx.subscriptions.push({

0 commit comments

Comments
 (0)