Skip to content

Commit 9d4b19f

Browse files
committed
Merge remote-tracking branch 'origin/main' into koesie10/ast-cfg-typed-commands
2 parents 9d6c78b + 8a66bb4 commit 9d4b19f

File tree

10 files changed

+140
-242
lines changed

10 files changed

+140
-242
lines changed

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

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ import type { Uri, Range } from "vscode";
33
import type { DbTreeViewItem } from "../databases/ui/db-tree-view-item";
44
import type { DatabaseItem } from "../local-databases";
55
import type { QueryHistoryInfo } from "../query-history/query-history-info";
6+
import type { RepositoriesFilterSortStateWithIds } from "../pure/variant-analysis-filter-sort";
7+
import type {
8+
VariantAnalysis,
9+
VariantAnalysisScannedRepository,
10+
VariantAnalysisScannedRepositoryResult,
11+
} from "../variant-analysis/shared/variant-analysis";
612

713
// A command function matching the signature that VS Code calls when
814
// a command on a selection is invoked.
@@ -27,6 +33,8 @@ export type SingleSelectionCommandFunction<Item> = (
2733
// Base commands not tied directly to a module like e.g. variant analysis.
2834
export type BaseCommands = {
2935
"codeQL.openDocumentation": () => Promise<void>;
36+
37+
"codeQL.restartQueryServer": () => Promise<void>;
3038
};
3139

3240
// Commands used for running local queries
@@ -74,6 +82,9 @@ export type QueryHistoryCommands = {
7482
"codeQLQueryHistory.itemClicked": SelectionCommandFunction<QueryHistoryInfo>;
7583
"codeQLQueryHistory.openOnGithub": SelectionCommandFunction<QueryHistoryInfo>;
7684
"codeQLQueryHistory.copyRepoList": SelectionCommandFunction<QueryHistoryInfo>;
85+
86+
// Commands in the command palette
87+
"codeQL.exportSelectedVariantAnalysisResults": () => Promise<void>;
7788
};
7889

7990
// Commands used for the local databases panel
@@ -118,9 +129,27 @@ export type LocalDatabasesCommands = {
118129

119130
// Commands tied to variant analysis
120131
export type VariantAnalysisCommands = {
132+
"codeQL.autoDownloadVariantAnalysisResult": (
133+
scannedRepo: VariantAnalysisScannedRepository,
134+
variantAnalysisSummary: VariantAnalysis,
135+
) => Promise<void>;
136+
"codeQL.copyVariantAnalysisRepoList": (
137+
variantAnalysisId: number,
138+
filterSort?: RepositoriesFilterSortStateWithIds,
139+
) => Promise<void>;
140+
"codeQL.loadVariantAnalysisRepoResults": (
141+
variantAnalysisId: number,
142+
repositoryFullName: string,
143+
) => Promise<VariantAnalysisScannedRepositoryResult>;
144+
"codeQL.monitorVariantAnalysis": (
145+
variantAnalysis: VariantAnalysis,
146+
) => Promise<void>;
121147
"codeQL.openVariantAnalysisLogs": (
122148
variantAnalysisId: number,
123149
) => Promise<void>;
150+
"codeQL.openVariantAnalysisView": (
151+
variantAnalysisId: number,
152+
) => Promise<void>;
124153
"codeQL.runVariantAnalysis": (uri?: Uri) => Promise<void>;
125154
"codeQL.runVariantAnalysisContextEditor": (uri?: Uri) => Promise<void>;
126155
};
@@ -147,12 +176,23 @@ export type AstCfgCommands = {
147176
"codeQL.viewCfgContextEditor": () => Promise<void>;
148177
};
149178

179+
export type PackagingCommands = {
180+
"codeQL.installPackDependencies": () => Promise<void>;
181+
"codeQL.downloadPacks": () => Promise<void>;
182+
};
183+
184+
export type EvalLogViewerCommands = {
185+
"codeQLEvalLogViewer.clear": () => Promise<void>;
186+
};
187+
150188
export type AllCommands = BaseCommands &
151189
QueryHistoryCommands &
152190
LocalDatabasesCommands &
153191
VariantAnalysisCommands &
154192
DatabasePanelCommands &
155-
AstCfgCommands;
193+
AstCfgCommands &
194+
PackagingCommands &
195+
EvalLogViewerCommands;
156196

157197
export type AppCommandManager = CommandManager<AllCommands>;
158198

extensions/ql-vscode/src/eval-log-viewer.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import {
88
EventEmitter,
99
TreeItemCollapsibleState,
1010
} from "vscode";
11-
import { commandRunner } from "./commandRunner";
1211
import { DisposableObject } from "./pure/disposable-object";
1312
import { showAndLogExceptionWithTelemetry } from "./helpers";
1413
import { asError, getErrorMessage } from "./pure/helpers-pure";
1514
import { redactableError } from "./pure/errors";
15+
import { EvalLogViewerCommands } from "./common/commands";
1616

1717
export interface EvalLogTreeItem {
1818
label?: string;
@@ -80,11 +80,12 @@ export class EvalLogViewer extends DisposableObject {
8080

8181
this.push(this.treeView);
8282
this.push(this.treeDataProvider);
83-
this.push(
84-
commandRunner("codeQLEvalLogViewer.clear", async () => {
85-
this.clear();
86-
}),
87-
);
83+
}
84+
85+
public getCommands(): EvalLogViewerCommands {
86+
return {
87+
"codeQLEvalLogViewer.clear": async () => this.clear(),
88+
};
8889
}
8990

9091
private clear(): void {

extensions/ql-vscode/src/extension.ts

Lines changed: 25 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,10 @@ import { QLTestAdapterFactory } from "./test-adapter";
8989
import { TestUIService } from "./test-ui";
9090
import { CompareView } from "./compare/compare-view";
9191
import { initializeTelemetry } from "./telemetry";
92-
import {
93-
commandRunner,
94-
commandRunnerWithProgress,
95-
ProgressCallback,
96-
withProgress,
97-
} from "./commandRunner";
92+
import { commandRunner, ProgressCallback, withProgress } from "./commandRunner";
9893
import { CodeQlStatusBarHandler } from "./status-bar";
99-
import {
100-
handleDownloadPacks,
101-
handleInstallPackDependencies,
102-
} from "./packaging";
94+
import { getPackagingCommands } from "./packaging";
10395
import { HistoryItemLabelProvider } from "./query-history/history-item-label-provider";
104-
import { exportSelectedVariantAnalysisResults } from "./variant-analysis/export-results";
10596
import { EvalLogViewer } from "./eval-log-viewer";
10697
import { SummaryLanguageSupport } from "./log-insights/summary-language-support";
10798
import { JoinOrderScannerProvider } from "./log-insights/join-order";
@@ -111,16 +102,11 @@ import { NewQueryRunner } from "./query-server/query-runner";
111102
import { QueryRunner } from "./queryRunner";
112103
import { VariantAnalysisView } from "./variant-analysis/variant-analysis-view";
113104
import { VariantAnalysisViewSerializer } from "./variant-analysis/variant-analysis-view-serializer";
114-
import {
115-
VariantAnalysis,
116-
VariantAnalysisScannedRepository,
117-
} from "./variant-analysis/shared/variant-analysis";
118105
import { VariantAnalysisManager } from "./variant-analysis/variant-analysis-manager";
119106
import { createVariantAnalysisContentProvider } from "./variant-analysis/variant-analysis-content-provider";
120107
import { VSCodeMockGitHubApiServer } from "./mocks/vscode-mock-gh-api-server";
121108
import { VariantAnalysisResultsManager } from "./variant-analysis/variant-analysis-results-manager";
122109
import { ExtensionApp } from "./common/vscode/vscode-app";
123-
import { RepositoriesFilterSortStateWithIds } from "./pure/variant-analysis-filter-sort";
124110
import { DbModule } from "./databases/db-module";
125111
import { redactableError } from "./pure/errors";
126112
import { QueryHistoryDirs } from "./query-history/query-history-dirs";
@@ -169,11 +155,28 @@ const extension = extensions.getExtension(extensionId);
169155
/**
170156
* Return all commands that are not tied to the more specific managers.
171157
*/
172-
function getCommands(): BaseCommands {
158+
function getCommands(
159+
cliServer: CodeQLCliServer,
160+
queryRunner: QueryRunner,
161+
): BaseCommands {
173162
return {
174163
"codeQL.openDocumentation": async () => {
175164
await env.openExternal(Uri.parse("https://codeql.github.com/docs/"));
176165
},
166+
"codeQL.restartQueryServer": async () =>
167+
withProgress(
168+
async (progress: ProgressCallback, token: CancellationToken) => {
169+
// We restart the CLI server too, to ensure they are the same version
170+
cliServer.restartCliServer();
171+
await queryRunner.restartQueryServer(progress, token);
172+
void showAndLogInformationMessage("CodeQL Query Server restarted.", {
173+
outputLogger: queryServerLogger,
174+
});
175+
},
176+
{
177+
title: "Restarting Query Server",
178+
},
179+
),
177180
};
178181
}
179182

@@ -819,7 +822,7 @@ async function activateWithInstalledDistribution(
819822
void extLogger.log("Registering top-level command palette commands.");
820823

821824
const allCommands: AllCommands = {
822-
...getCommands(),
825+
...getCommands(cliServer, qs),
823826
...qhm.getCommands(),
824827
...variantAnalysisManager.getCommands(),
825828
...databaseUI.getCommands(),
@@ -834,6 +837,10 @@ async function activateWithInstalledDistribution(
834837
astTemplateProvider,
835838
cfgTemplateProvider,
836839
}),
840+
...getPackagingCommands({
841+
cliServer,
842+
}),
843+
...evalLogViewer.getCommands(),
837844
};
838845

839846
for (const [commandName, command] of Object.entries(allCommands)) {
@@ -860,78 +867,6 @@ async function activateWithInstalledDistribution(
860867
);
861868
}
862869

863-
ctx.subscriptions.push(
864-
commandRunner(
865-
"codeQL.copyVariantAnalysisRepoList",
866-
async (
867-
variantAnalysisId: number,
868-
filterSort?: RepositoriesFilterSortStateWithIds,
869-
) => {
870-
await variantAnalysisManager.copyRepoListToClipboard(
871-
variantAnalysisId,
872-
filterSort,
873-
);
874-
},
875-
),
876-
);
877-
878-
ctx.subscriptions.push(
879-
commandRunner(
880-
"codeQL.monitorVariantAnalysis",
881-
async (variantAnalysis: VariantAnalysis, token: CancellationToken) => {
882-
await variantAnalysisManager.monitorVariantAnalysis(
883-
variantAnalysis,
884-
token,
885-
);
886-
},
887-
),
888-
);
889-
890-
ctx.subscriptions.push(
891-
commandRunner(
892-
"codeQL.autoDownloadVariantAnalysisResult",
893-
async (
894-
scannedRepo: VariantAnalysisScannedRepository,
895-
variantAnalysisSummary: VariantAnalysis,
896-
token: CancellationToken,
897-
) => {
898-
await variantAnalysisManager.enqueueDownload(
899-
scannedRepo,
900-
variantAnalysisSummary,
901-
token,
902-
);
903-
},
904-
),
905-
);
906-
907-
ctx.subscriptions.push(
908-
commandRunner("codeQL.exportSelectedVariantAnalysisResults", async () => {
909-
await exportSelectedVariantAnalysisResults(variantAnalysisManager, qhm);
910-
}),
911-
);
912-
913-
ctx.subscriptions.push(
914-
commandRunner(
915-
"codeQL.loadVariantAnalysisRepoResults",
916-
async (variantAnalysisId: number, repositoryFullName: string) => {
917-
await variantAnalysisManager.loadResults(
918-
variantAnalysisId,
919-
repositoryFullName,
920-
);
921-
},
922-
),
923-
);
924-
925-
// The "openVariantAnalysisView" command is internal-only.
926-
ctx.subscriptions.push(
927-
commandRunner(
928-
"codeQL.openVariantAnalysisView",
929-
async (variantAnalysisId: number) => {
930-
await variantAnalysisManager.showView(variantAnalysisId);
931-
},
932-
),
933-
);
934-
935870
ctx.subscriptions.push(
936871
commandRunner("codeQL.openReferencedFile", async (selectedQuery: Uri) => {
937872
await openReferencedFile(qs, cliServer, selectedQuery);
@@ -964,23 +899,6 @@ async function activateWithInstalledDistribution(
964899
}),
965900
);
966901

967-
ctx.subscriptions.push(
968-
commandRunnerWithProgress(
969-
"codeQL.restartQueryServer",
970-
async (progress: ProgressCallback, token: CancellationToken) => {
971-
// We restart the CLI server too, to ensure they are the same version
972-
cliServer.restartCliServer();
973-
await qs.restartQueryServer(progress, token);
974-
void showAndLogInformationMessage("CodeQL Query Server restarted.", {
975-
outputLogger: queryServerLogger,
976-
});
977-
},
978-
{
979-
title: "Restarting Query Server",
980-
},
981-
),
982-
);
983-
984902
ctx.subscriptions.push(
985903
commandRunner("codeQL.copyVersion", async () => {
986904
const text = `CodeQL extension version: ${
@@ -1013,28 +931,6 @@ async function activateWithInstalledDistribution(
1013931
}),
1014932
);
1015933

1016-
ctx.subscriptions.push(
1017-
commandRunnerWithProgress(
1018-
"codeQL.installPackDependencies",
1019-
async (progress: ProgressCallback) =>
1020-
await handleInstallPackDependencies(cliServer, progress),
1021-
{
1022-
title: "Installing pack dependencies",
1023-
},
1024-
),
1025-
);
1026-
1027-
ctx.subscriptions.push(
1028-
commandRunnerWithProgress(
1029-
"codeQL.downloadPacks",
1030-
async (progress: ProgressCallback) =>
1031-
await handleDownloadPacks(cliServer, progress),
1032-
{
1033-
title: "Downloading packs",
1034-
},
1035-
),
1036-
);
1037-
1038934
ctx.subscriptions.push(
1039935
commandRunner("codeQL.showLogs", async () => {
1040936
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)