diff --git a/extensions/ql-vscode/src/common/commands.ts b/extensions/ql-vscode/src/common/commands.ts index 4f1c82355..a41a57b8f 100644 --- a/extensions/ql-vscode/src/common/commands.ts +++ b/extensions/ql-vscode/src/common/commands.ts @@ -39,6 +39,13 @@ export type BuiltInVsCodeCommands = { "workbench.action.reloadWindow": () => Promise; }; +// Commands that are available before the extension is fully activated. +// These commands are *not* registered using the command manager, but can +// be invoked using the command manager. +export type PreActivationCommands = { + "codeQL.checkForUpdatesToCLI": () => Promise; +}; + // Base commands not tied directly to a module like e.g. variant analysis. export type BaseCommands = { "codeQL.openDocumentation": () => Promise; @@ -240,7 +247,7 @@ export type MockGitHubApiServerCommands = { "codeQL.mockGitHubApiServer.unloadScenario": () => Promise; }; -// All commands where the implementation is provided by this extension. +// All commands where the implementation is provided by this activated extension. export type AllExtensionCommands = BaseCommands & QueryEditorCommands & ResultsViewCommands & @@ -256,7 +263,9 @@ export type AllExtensionCommands = BaseCommands & Partial & MockGitHubApiServerCommands; -export type AllCommands = AllExtensionCommands & BuiltInVsCodeCommands; +export type AllCommands = AllExtensionCommands & + PreActivationCommands & + BuiltInVsCodeCommands; export type AppCommandManager = CommandManager; diff --git a/extensions/ql-vscode/src/extension.ts b/extensions/ql-vscode/src/extension.ts index 669560b34..63ece980d 100644 --- a/extensions/ql-vscode/src/extension.ts +++ b/extensions/ql-vscode/src/extension.ts @@ -112,6 +112,7 @@ import { QueryHistoryDirs } from "./query-history/query-history-dirs"; import { AllExtensionCommands, BaseCommands, + PreActivationCommands, QueryServerCommands, TestUICommands, } from "./common/commands"; @@ -235,6 +236,8 @@ function registerErrorStubs( stubbedCommands.forEach((command) => { if (excludedCommands.indexOf(command) === -1) { + // This is purposefully using `commandRunner` instead of the command manager because these + // commands are untyped and registered pre-activation. errorStubs.push(commandRunner(command, stubGenerator(command))); } }); @@ -336,6 +339,8 @@ export async function activate( ), ); ctx.subscriptions.push( + // This is purposefully using `commandRunner` directly instead of the command manager + // because this command is registered pre-activation. commandRunner(checkForUpdatesCommand, () => installOrUpdateThenTryActivate( ctx, @@ -1089,7 +1094,8 @@ async function initializeLogging(ctx: ExtensionContext): Promise { ctx.subscriptions.push(ideServerLogger); } -const checkForUpdatesCommand = "codeQL.checkForUpdatesToCLI"; +const checkForUpdatesCommand: keyof PreActivationCommands = + "codeQL.checkForUpdatesToCLI" as const; const avoidVersionCheck = "avoid-version-check-at-startup"; const lastVersionChecked = "last-version-checked";