Skip to content

Commit 8a66bb4

Browse files
authored
Merge pull request #2198 from github/koesie10/packaging-typed-commands
Convert packaging to typed commands
2 parents e55fb8c + 5c06bcc commit 8a66bb4

File tree

3 files changed

+43
-27
lines changed

3 files changed

+43
-27
lines changed

extensions/ql-vscode/src/common/commands.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ export type DatabasePanelCommands = {
167167
"codeQLVariantAnalysisRepositories.removeItemContextMenu": SingleSelectionCommandFunction<DbTreeViewItem>;
168168
};
169169

170+
export type PackagingCommands = {
171+
"codeQL.installPackDependencies": () => Promise<void>;
172+
"codeQL.downloadPacks": () => Promise<void>;
173+
};
174+
170175
export type EvalLogViewerCommands = {
171176
"codeQLEvalLogViewer.clear": () => Promise<void>;
172177
};
@@ -176,6 +181,7 @@ export type AllCommands = BaseCommands &
176181
LocalDatabasesCommands &
177182
VariantAnalysisCommands &
178183
DatabasePanelCommands &
184+
PackagingCommands &
179185
EvalLogViewerCommands;
180186

181187
export type AppCommandManager = CommandManager<AllCommands>;

extensions/ql-vscode/src/extension.ts

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,7 @@ import {
9696
withProgress,
9797
} from "./commandRunner";
9898
import { CodeQlStatusBarHandler } from "./status-bar";
99-
import {
100-
handleDownloadPacks,
101-
handleInstallPackDependencies,
102-
} from "./packaging";
99+
import { getPackagingCommands } from "./packaging";
103100
import { HistoryItemLabelProvider } from "./query-history/history-item-label-provider";
104101
import { EvalLogViewer } from "./eval-log-viewer";
105102
import { SummaryLanguageSupport } from "./log-insights/summary-language-support";
@@ -815,6 +812,9 @@ async function activateWithInstalledDistribution(
815812
...variantAnalysisManager.getCommands(),
816813
...databaseUI.getCommands(),
817814
...dbModule.getCommands(),
815+
...getPackagingCommands({
816+
cliServer,
817+
}),
818818
...evalLogViewer.getCommands(),
819819
};
820820

@@ -906,28 +906,6 @@ async function activateWithInstalledDistribution(
906906
}),
907907
);
908908

909-
ctx.subscriptions.push(
910-
commandRunnerWithProgress(
911-
"codeQL.installPackDependencies",
912-
async (progress: ProgressCallback) =>
913-
await handleInstallPackDependencies(cliServer, progress),
914-
{
915-
title: "Installing pack dependencies",
916-
},
917-
),
918-
);
919-
920-
ctx.subscriptions.push(
921-
commandRunnerWithProgress(
922-
"codeQL.downloadPacks",
923-
async (progress: ProgressCallback) =>
924-
await handleDownloadPacks(cliServer, progress),
925-
{
926-
title: "Downloading packs",
927-
},
928-
),
929-
);
930-
931909
ctx.subscriptions.push(
932910
commandRunner("codeQL.showLogs", async () => {
933911
extLogger.show();

extensions/ql-vscode/src/packaging.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,43 @@ import {
55
showAndLogInformationMessage,
66
} from "./helpers";
77
import { QuickPickItem, window } from "vscode";
8-
import { ProgressCallback, UserCancellationException } from "./commandRunner";
8+
import {
9+
ProgressCallback,
10+
UserCancellationException,
11+
withProgress,
12+
} from "./commandRunner";
913
import { extLogger } from "./common";
1014
import { asError, getErrorStack } from "./pure/helpers-pure";
1115
import { redactableError } from "./pure/errors";
1216
import { PACKS_BY_QUERY_LANGUAGE } from "./common/query-language";
17+
import { PackagingCommands } from "./common/commands";
18+
19+
type PackagingOptions = {
20+
cliServer: CodeQLCliServer;
21+
};
22+
23+
export function getPackagingCommands({
24+
cliServer,
25+
}: PackagingOptions): PackagingCommands {
26+
return {
27+
"codeQL.installPackDependencies": async () =>
28+
withProgress(
29+
async (progress: ProgressCallback) =>
30+
await handleInstallPackDependencies(cliServer, progress),
31+
{
32+
title: "Installing pack dependencies",
33+
},
34+
),
35+
"codeQL.downloadPacks": async () =>
36+
withProgress(
37+
async (progress: ProgressCallback) =>
38+
await handleDownloadPacks(cliServer, progress),
39+
{
40+
title: "Downloading packs",
41+
},
42+
),
43+
};
44+
}
1345

1446
/**
1547
* Prompts user to choose packs to download, and downloads them.

0 commit comments

Comments
 (0)