diff --git a/extensions/ql-vscode/src/common/commands.ts b/extensions/ql-vscode/src/common/commands.ts index a4ea3fb0f..4f1c82355 100644 --- a/extensions/ql-vscode/src/common/commands.ts +++ b/extensions/ql-vscode/src/common/commands.ts @@ -42,7 +42,10 @@ export type BuiltInVsCodeCommands = { // Base commands not tied directly to a module like e.g. variant analysis. export type BaseCommands = { "codeQL.openDocumentation": () => Promise; + "codeQL.showLogs": () => Promise; + "codeQL.authenticateToGitHub": () => Promise; + "codeQL.copyVersion": () => Promise; "codeQL.restartQueryServer": () => Promise; }; diff --git a/extensions/ql-vscode/src/extension.ts b/extensions/ql-vscode/src/extension.ts index a63ba9b45..669560b34 100644 --- a/extensions/ql-vscode/src/extension.ts +++ b/extensions/ql-vscode/src/extension.ts @@ -121,6 +121,7 @@ import { } from "./local-queries"; import { getAstCfgCommands } from "./ast-cfg-commands"; import { getQueryEditorCommands } from "./query-editor"; +import { App } from "./common/app"; /** * extension.ts @@ -156,9 +157,18 @@ const extension = extensions.getExtension(extensionId); * Return all commands that are not tied to the more specific managers. */ function getCommands( + app: App, cliServer: CodeQLCliServer, queryRunner: QueryRunner, ): BaseCommands { + const getCliVersion = async () => { + try { + return await cliServer.getVersion(); + } catch { + return ""; + } + }; + return { "codeQL.openDocumentation": async () => { await env.openExternal(Uri.parse("https://codeql.github.com/docs/")); @@ -177,6 +187,27 @@ function getCommands( title: "Restarting Query Server", }, ), + "codeQL.copyVersion": async () => { + const text = `CodeQL extension version: ${ + extension?.packageJSON.version + } \nCodeQL CLI version: ${await getCliVersion()} \nPlatform: ${platform()} ${arch()}`; + await env.clipboard.writeText(text); + void showAndLogInformationMessage(text); + }, + "codeQL.authenticateToGitHub": async () => { + /** + * Credentials for authenticating to GitHub. + * These are used when making API calls. + */ + const octokit = await app.credentials.getOctokit(); + const userInfo = await octokit.users.getAuthenticated(); + void showAndLogInformationMessage( + `Authenticated to GitHub as user: ${userInfo.data.login}`, + ); + }, + "codeQL.showLogs": async () => { + extLogger.show(); + }, }; } @@ -841,7 +872,7 @@ async function activateWithInstalledDistribution( void extLogger.log("Registering top-level command palette commands."); const allCommands: AllExtensionCommands = { - ...getCommands(cliServer, qs), + ...getCommands(app, cliServer, qs), ...getQueryEditorCommands({ queryRunner: qs, cliServer, @@ -896,44 +927,6 @@ async function activateWithInstalledDistribution( ); } - ctx.subscriptions.push( - commandRunner("codeQL.copyVersion", async () => { - const text = `CodeQL extension version: ${ - extension?.packageJSON.version - } \nCodeQL CLI version: ${await getCliVersion()} \nPlatform: ${platform()} ${arch()}`; - await env.clipboard.writeText(text); - void showAndLogInformationMessage(text); - }), - ); - - const getCliVersion = async () => { - try { - return await cliServer.getVersion(); - } catch { - return ""; - } - }; - - ctx.subscriptions.push( - commandRunner("codeQL.authenticateToGitHub", async () => { - /** - * Credentials for authenticating to GitHub. - * These are used when making API calls. - */ - const octokit = await app.credentials.getOctokit(); - const userInfo = await octokit.users.getAuthenticated(); - void showAndLogInformationMessage( - `Authenticated to GitHub as user: ${userInfo.data.login}`, - ); - }), - ); - - ctx.subscriptions.push( - commandRunner("codeQL.showLogs", async () => { - extLogger.show(); - }), - ); - void extLogger.log("Starting language server."); await client.start(); ctx.subscriptions.push({