Merge pull request #2207 from github/robertbrignull/extension_commands
Start using app.commands.execute for all commands called from extension.ts
This commit is contained in:
@@ -32,6 +32,13 @@ export type SingleSelectionCommandFunction<Item> = (
|
||||
* the implementation in the corresponding `getCommands` function.
|
||||
*/
|
||||
|
||||
// Builtin commands where the implementation is provided by VS Code and not by this extension.
|
||||
// See https://code.visualstudio.com/api/references/commands
|
||||
export type BuiltInVsCodeCommands = {
|
||||
"markdown.showPreviewToSide": (uri: Uri) => Promise<void>;
|
||||
"workbench.action.reloadWindow": () => Promise<void>;
|
||||
};
|
||||
|
||||
// Base commands not tied directly to a module like e.g. variant analysis.
|
||||
export type BaseCommands = {
|
||||
"codeQL.openDocumentation": () => Promise<void>;
|
||||
@@ -230,7 +237,8 @@ export type MockGitHubApiServerCommands = {
|
||||
"codeQL.mockGitHubApiServer.unloadScenario": () => Promise<void>;
|
||||
};
|
||||
|
||||
export type AllCommands = BaseCommands &
|
||||
// All commands where the implementation is provided by this extension.
|
||||
export type AllExtensionCommands = BaseCommands &
|
||||
QueryEditorCommands &
|
||||
ResultsViewCommands &
|
||||
QueryHistoryCommands &
|
||||
@@ -245,6 +253,8 @@ export type AllCommands = BaseCommands &
|
||||
Partial<TestUICommands> &
|
||||
MockGitHubApiServerCommands;
|
||||
|
||||
export type AllCommands = AllExtensionCommands & BuiltInVsCodeCommands;
|
||||
|
||||
export type AppCommandManager = CommandManager<AllCommands>;
|
||||
|
||||
// Separate command manager because it uses a different logger
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import "source-map-support/register";
|
||||
import {
|
||||
CancellationToken,
|
||||
commands,
|
||||
Disposable,
|
||||
env,
|
||||
ExtensionContext,
|
||||
@@ -111,7 +110,7 @@ import { DbModule } from "./databases/db-module";
|
||||
import { redactableError } from "./pure/errors";
|
||||
import { QueryHistoryDirs } from "./query-history/query-history-dirs";
|
||||
import {
|
||||
AllCommands,
|
||||
AllExtensionCommands,
|
||||
BaseCommands,
|
||||
QueryServerCommands,
|
||||
TestUICommands,
|
||||
@@ -266,6 +265,8 @@ export async function activate(
|
||||
addUnhandledRejectionListener();
|
||||
install();
|
||||
|
||||
const app = new ExtensionApp(ctx);
|
||||
|
||||
const codelensProvider = new QuickEvalCodeLensProvider();
|
||||
languages.registerCodeLensProvider(
|
||||
{ scheme: "file", language: "ql" },
|
||||
@@ -292,6 +293,7 @@ export async function activate(
|
||||
distributionConfigListener.onDidChangeConfiguration(() =>
|
||||
installOrUpdateThenTryActivate(
|
||||
ctx,
|
||||
app,
|
||||
distributionManager,
|
||||
distributionConfigListener,
|
||||
{
|
||||
@@ -306,6 +308,7 @@ export async function activate(
|
||||
commandRunner(checkForUpdatesCommand, () =>
|
||||
installOrUpdateThenTryActivate(
|
||||
ctx,
|
||||
app,
|
||||
distributionManager,
|
||||
distributionConfigListener,
|
||||
{
|
||||
@@ -325,6 +328,7 @@ export async function activate(
|
||||
|
||||
const codeQlExtension = await installOrUpdateThenTryActivate(
|
||||
ctx,
|
||||
app,
|
||||
distributionManager,
|
||||
distributionConfigListener,
|
||||
{
|
||||
@@ -346,6 +350,7 @@ export async function activate(
|
||||
|
||||
async function installOrUpdateDistributionWithProgressTitle(
|
||||
ctx: ExtensionContext,
|
||||
app: ExtensionApp,
|
||||
distributionManager: DistributionManager,
|
||||
progressTitle: string,
|
||||
config: DistributionUpdateConfig,
|
||||
@@ -390,7 +395,7 @@ async function installOrUpdateDistributionWithProgressTitle(
|
||||
"Restart and Upgrade",
|
||||
)
|
||||
) {
|
||||
await commands.executeCommand("workbench.action.reloadWindow");
|
||||
await app.commands.execute("workbench.action.reloadWindow");
|
||||
}
|
||||
} else {
|
||||
await withProgress(
|
||||
@@ -417,6 +422,7 @@ async function installOrUpdateDistributionWithProgressTitle(
|
||||
|
||||
async function installOrUpdateDistribution(
|
||||
ctx: ExtensionContext,
|
||||
app: ExtensionApp,
|
||||
distributionManager: DistributionManager,
|
||||
config: DistributionUpdateConfig,
|
||||
): Promise<void> {
|
||||
@@ -437,6 +443,7 @@ async function installOrUpdateDistribution(
|
||||
try {
|
||||
await installOrUpdateDistributionWithProgressTitle(
|
||||
ctx,
|
||||
app,
|
||||
distributionManager,
|
||||
messageText,
|
||||
config,
|
||||
@@ -522,11 +529,12 @@ async function getDistributionDisplayingDistributionWarnings(
|
||||
|
||||
async function installOrUpdateThenTryActivate(
|
||||
ctx: ExtensionContext,
|
||||
app: ExtensionApp,
|
||||
distributionManager: DistributionManager,
|
||||
distributionConfigListener: DistributionConfigListener,
|
||||
config: DistributionUpdateConfig,
|
||||
): Promise<CodeQLExtensionInterface | Record<string, never>> {
|
||||
await installOrUpdateDistribution(ctx, distributionManager, config);
|
||||
await installOrUpdateDistribution(ctx, app, distributionManager, config);
|
||||
|
||||
try {
|
||||
await prepareCodeTour();
|
||||
@@ -546,6 +554,7 @@ async function installOrUpdateThenTryActivate(
|
||||
) {
|
||||
extensionInterface = await activateWithInstalledDistribution(
|
||||
ctx,
|
||||
app,
|
||||
distributionManager,
|
||||
distributionConfigListener,
|
||||
);
|
||||
@@ -563,6 +572,7 @@ async function installOrUpdateThenTryActivate(
|
||||
if (chosenAction === installActionName) {
|
||||
await installOrUpdateThenTryActivate(
|
||||
ctx,
|
||||
app,
|
||||
distributionManager,
|
||||
distributionConfigListener,
|
||||
{
|
||||
@@ -589,6 +599,7 @@ const PACK_GLOBS = [
|
||||
|
||||
async function activateWithInstalledDistribution(
|
||||
ctx: ExtensionContext,
|
||||
app: ExtensionApp,
|
||||
distributionManager: DistributionManager,
|
||||
distributionConfigListener: DistributionConfigListener,
|
||||
): Promise<CodeQLExtensionInterface> {
|
||||
@@ -597,8 +608,6 @@ async function activateWithInstalledDistribution(
|
||||
// of activation.
|
||||
errorStubs.forEach((stub) => stub.dispose());
|
||||
|
||||
const app = new ExtensionApp(ctx);
|
||||
|
||||
void extLogger.log("Initializing configuration listener...");
|
||||
const qlConfigurationListener =
|
||||
await QueryServerConfigListener.createQueryServerConfigListener(
|
||||
@@ -831,7 +840,7 @@ async function activateWithInstalledDistribution(
|
||||
|
||||
void extLogger.log("Registering top-level command palette commands.");
|
||||
|
||||
const allCommands: AllCommands = {
|
||||
const allCommands: AllExtensionCommands = {
|
||||
...getCommands(cliServer, qs),
|
||||
...getQueryEditorCommands({
|
||||
queryRunner: qs,
|
||||
@@ -864,7 +873,7 @@ async function activateWithInstalledDistribution(
|
||||
};
|
||||
|
||||
for (const [commandName, command] of Object.entries(allCommands)) {
|
||||
app.commands.register(commandName as keyof AllCommands, command);
|
||||
app.commands.register(commandName as keyof AllExtensionCommands, command);
|
||||
}
|
||||
|
||||
const queryServerCommands: QueryServerCommands = {
|
||||
@@ -955,7 +964,7 @@ async function activateWithInstalledDistribution(
|
||||
),
|
||||
);
|
||||
|
||||
await commands.executeCommand("codeQLDatabases.removeOrphanedDatabases");
|
||||
await app.commands.execute("codeQLDatabases.removeOrphanedDatabases");
|
||||
|
||||
void extLogger.log("Reading query history");
|
||||
await qhm.readQueryHistory();
|
||||
|
||||
Reference in New Issue
Block a user