From 81cce9fa8b67324ea18fe4816a998fb01f1af952 Mon Sep 17 00:00:00 2001 From: Koen Vlaswinkel Date: Wed, 22 Mar 2023 17:19:45 +0100 Subject: [PATCH] Add `codeQL.checkForUpdatesToCLI` type for command The `codeQL.checkForUpdatesToCLI` command is registered pre-activation, and we don't really want to create the command manager before activation, so this will just add the correct type without registering it using the command manager. --- extensions/ql-vscode/src/common/commands.ts | 13 +++++++++++-- extensions/ql-vscode/src/extension.ts | 8 +++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/extensions/ql-vscode/src/common/commands.ts b/extensions/ql-vscode/src/common/commands.ts index a4ea3fb0f..a652d74d7 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; @@ -237,7 +244,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 & @@ -253,7 +260,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 a63ba9b45..3a99ac4ea 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"; @@ -204,6 +205,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))); } }); @@ -305,6 +308,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, @@ -1096,7 +1101,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";