Convert packaging commands to typed commands

This commit is contained in:
Koen Vlaswinkel
2023-03-21 16:53:33 +01:00
parent dfff7ae8de
commit 7c7a64ca5b
3 changed files with 20 additions and 21 deletions

View File

@@ -108,10 +108,16 @@ export type DatabasePanelCommands = {
"codeQLVariantAnalysisRepositories.removeItemContextMenu": SingleSelectionCommandFunction<DbTreeViewItem>;
};
export type PackagingCommands = {
"codeQL.installPackDependencies": () => Promise<void>;
"codeQL.downloadPacks": () => Promise<void>;
};
export type AllCommands = BaseCommands &
QueryHistoryCommands &
LocalDatabasesCommands &
VariantAnalysisCommands &
DatabasePanelCommands;
DatabasePanelCommands &
PackagingCommands;
export type AppCommandManager = CommandManager<AllCommands>;

View File

@@ -103,7 +103,7 @@ import {
withProgress,
} from "./commandRunner";
import { CodeQlStatusBarHandler } from "./status-bar";
import { registerPackagingCommands } from "./packaging";
import { getPackagingCommands } from "./packaging";
import { HistoryItemLabelProvider } from "./query-history/history-item-label-provider";
import { exportSelectedVariantAnalysisResults } from "./variant-analysis/export-results";
import { EvalLogViewer } from "./eval-log-viewer";
@@ -1090,6 +1090,9 @@ async function activateWithInstalledDistribution(
...variantAnalysisManager.getCommands(),
...databaseUI.getCommands(),
...dbModule.getCommands(),
...getPackagingCommands({
cliServer,
}),
};
for (const [commandName, command] of Object.entries(allCommands)) {
@@ -1292,10 +1295,6 @@ async function activateWithInstalledDistribution(
}),
);
registerPackagingCommands(ctx, {
cliServer,
});
ctx.subscriptions.push(
commandRunner("codeQL.showLogs", async () => {
extLogger.show();

View File

@@ -4,9 +4,8 @@ import {
showAndLogExceptionWithTelemetry,
showAndLogInformationMessage,
} from "./helpers";
import { ExtensionContext, QuickPickItem, window } from "vscode";
import { QuickPickItem, window } from "vscode";
import {
commandRunner,
ProgressCallback,
UserCancellationException,
withProgress,
@@ -15,17 +14,17 @@ import { extLogger } from "./common";
import { asError, getErrorStack } from "./pure/helpers-pure";
import { redactableError } from "./pure/errors";
import { PACKS_BY_QUERY_LANGUAGE } from "./common/query-language";
import { PackagingCommands } from "./common/commands";
type PackagingOptions = {
cliServer: CodeQLCliServer;
};
export function registerPackagingCommands(
ctx: ExtensionContext,
{ cliServer }: PackagingOptions,
) {
ctx.subscriptions.push(
commandRunner("codeQL.installPackDependencies", async () =>
export function getPackagingCommands({
cliServer,
}: PackagingOptions): PackagingCommands {
return {
"codeQL.installPackDependencies": async () =>
withProgress(
async (progress: ProgressCallback) =>
await handleInstallPackDependencies(cliServer, progress),
@@ -33,11 +32,7 @@ export function registerPackagingCommands(
title: "Installing pack dependencies",
},
),
),
);
ctx.subscriptions.push(
commandRunner("codeQL.downloadPacks", async () =>
"codeQL.downloadPacks": async () =>
withProgress(
async (progress: ProgressCallback) =>
await handleDownloadPacks(cliServer, progress),
@@ -45,8 +40,7 @@ export function registerPackagingCommands(
title: "Downloading packs",
},
),
),
);
};
}
/**