Skip to content

Commit a6fefdb

Browse files
Merge branch 'main' into robertbrignull/variant_analysis_commands
2 parents 0166f9a + 2334e4e commit a6fefdb

File tree

5 files changed

+57
-53
lines changed

5 files changed

+57
-53
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ export type SingleSelectionCommandFunction<Item> = (
3333
// Base commands not tied directly to a module like e.g. variant analysis.
3434
export type BaseCommands = {
3535
"codeQL.openDocumentation": () => Promise<void>;
36+
37+
"codeQL.restartQueryServer": () => Promise<void>;
3638
};
3739

3840
// Commands used for running local queries
@@ -80,6 +82,9 @@ export type QueryHistoryCommands = {
8082
"codeQLQueryHistory.itemClicked": SelectionCommandFunction<QueryHistoryInfo>;
8183
"codeQLQueryHistory.openOnGithub": SelectionCommandFunction<QueryHistoryInfo>;
8284
"codeQLQueryHistory.copyRepoList": SelectionCommandFunction<QueryHistoryInfo>;
85+
86+
// Commands in the command palette
87+
"codeQL.exportSelectedVariantAnalysisResults": () => Promise<void>;
8388
};
8489

8590
// Commands used for the local databases panel
@@ -162,11 +167,16 @@ export type DatabasePanelCommands = {
162167
"codeQLVariantAnalysisRepositories.removeItemContextMenu": SingleSelectionCommandFunction<DbTreeViewItem>;
163168
};
164169

170+
export type EvalLogViewerCommands = {
171+
"codeQLEvalLogViewer.clear": () => Promise<void>;
172+
};
173+
165174
export type AllCommands = BaseCommands &
166175
QueryHistoryCommands &
167176
LocalDatabasesCommands &
168177
VariantAnalysisCommands &
169-
DatabasePanelCommands;
178+
DatabasePanelCommands &
179+
EvalLogViewerCommands;
170180

171181
export type AppCommandManager = CommandManager<AllCommands>;
172182

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: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ import {
101101
handleInstallPackDependencies,
102102
} from "./packaging";
103103
import { HistoryItemLabelProvider } from "./query-history/history-item-label-provider";
104-
import { exportSelectedVariantAnalysisResults } from "./variant-analysis/export-results";
105104
import { EvalLogViewer } from "./eval-log-viewer";
106105
import { SummaryLanguageSupport } from "./log-insights/summary-language-support";
107106
import { JoinOrderScannerProvider } from "./log-insights/join-order";
@@ -164,11 +163,28 @@ const extension = extensions.getExtension(extensionId);
164163
/**
165164
* Return all commands that are not tied to the more specific managers.
166165
*/
167-
function getCommands(): BaseCommands {
166+
function getCommands(
167+
cliServer: CodeQLCliServer,
168+
queryRunner: QueryRunner,
169+
): BaseCommands {
168170
return {
169171
"codeQL.openDocumentation": async () => {
170172
await env.openExternal(Uri.parse("https://codeql.github.com/docs/"));
171173
},
174+
"codeQL.restartQueryServer": async () =>
175+
withProgress(
176+
async (progress: ProgressCallback, token: CancellationToken) => {
177+
// We restart the CLI server too, to ensure they are the same version
178+
cliServer.restartCliServer();
179+
await queryRunner.restartQueryServer(progress, token);
180+
void showAndLogInformationMessage("CodeQL Query Server restarted.", {
181+
outputLogger: queryServerLogger,
182+
});
183+
},
184+
{
185+
title: "Restarting Query Server",
186+
},
187+
),
172188
};
173189
}
174190

@@ -794,11 +810,12 @@ async function activateWithInstalledDistribution(
794810
void extLogger.log("Registering top-level command palette commands.");
795811

796812
const allCommands: AllCommands = {
797-
...getCommands(),
813+
...getCommands(cliServer, qs),
798814
...qhm.getCommands(),
799815
...variantAnalysisManager.getCommands(),
800816
...databaseUI.getCommands(),
801817
...dbModule.getCommands(),
818+
...evalLogViewer.getCommands(),
802819
};
803820

804821
for (const [commandName, command] of Object.entries(allCommands)) {
@@ -825,12 +842,6 @@ async function activateWithInstalledDistribution(
825842
);
826843
}
827844

828-
ctx.subscriptions.push(
829-
commandRunner("codeQL.exportSelectedVariantAnalysisResults", async () => {
830-
await exportSelectedVariantAnalysisResults(variantAnalysisManager, qhm);
831-
}),
832-
);
833-
834845
ctx.subscriptions.push(
835846
commandRunner("codeQL.openReferencedFile", async (selectedQuery: Uri) => {
836847
await openReferencedFile(qs, cliServer, selectedQuery);
@@ -863,23 +874,6 @@ async function activateWithInstalledDistribution(
863874
}),
864875
);
865876

866-
ctx.subscriptions.push(
867-
commandRunnerWithProgress(
868-
"codeQL.restartQueryServer",
869-
async (progress: ProgressCallback, token: CancellationToken) => {
870-
// We restart the CLI server too, to ensure they are the same version
871-
cliServer.restartCliServer();
872-
await qs.restartQueryServer(progress, token);
873-
void showAndLogInformationMessage("CodeQL Query Server restarted.", {
874-
outputLogger: queryServerLogger,
875-
});
876-
},
877-
{
878-
title: "Restarting Query Server",
879-
},
880-
),
881-
);
882-
883877
ctx.subscriptions.push(
884878
commandRunner("codeQL.copyVersion", async () => {
885879
const text = `CodeQL extension version: ${

extensions/ql-vscode/src/query-history/query-history-manager.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,9 @@ export class QueryHistoryManager extends DisposableObject {
271271
"codeQLQueryHistory.itemClicked": this.handleItemClicked.bind(this),
272272
"codeQLQueryHistory.openOnGithub": this.handleOpenOnGithub.bind(this),
273273
"codeQLQueryHistory.copyRepoList": this.handleCopyRepoList.bind(this),
274+
275+
"codeQL.exportSelectedVariantAnalysisResults":
276+
this.exportSelectedVariantAnalysisResults.bind(this),
274277
};
275278
}
276279

@@ -1127,6 +1130,22 @@ export class QueryHistoryManager extends DisposableObject {
11271130
);
11281131
}
11291132

1133+
/**
1134+
* Exports the results of the currently-selected variant analysis.
1135+
*/
1136+
async exportSelectedVariantAnalysisResults(): Promise<void> {
1137+
const queryHistoryItem = this.getCurrentQueryHistoryItem();
1138+
if (!queryHistoryItem || queryHistoryItem.t !== "variant-analysis") {
1139+
throw new Error(
1140+
"No variant analysis results currently open. To open results, click an item in the query history view.",
1141+
);
1142+
}
1143+
1144+
await this.variantAnalysisManager.exportResults(
1145+
queryHistoryItem.variantAnalysis.id,
1146+
);
1147+
}
1148+
11301149
addQuery(item: QueryHistoryInfo) {
11311150
this.treeDataProvider.pushQuery(item);
11321151
this.updateTreeViewSelectionIfVisible();

extensions/ql-vscode/src/variant-analysis/export-results.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import {
1616
} from "../commandRunner";
1717
import { showInformationMessageWithAction } from "../helpers";
1818
import { extLogger } from "../common";
19-
import { QueryHistoryManager } from "../query-history/query-history-manager";
2019
import { createGist } from "./gh-api/gh-api-client";
2120
import {
2221
generateVariantAnalysisMarkdown,
@@ -37,25 +36,6 @@ import {
3736
} from "../pure/variant-analysis-filter-sort";
3837
import { Credentials } from "../common/authentication";
3938

40-
/**
41-
* Exports the results of the currently-selected variant analysis.
42-
*/
43-
export async function exportSelectedVariantAnalysisResults(
44-
variantAnalysisManager: VariantAnalysisManager,
45-
queryHistoryManager: QueryHistoryManager,
46-
): Promise<void> {
47-
const queryHistoryItem = queryHistoryManager.getCurrentQueryHistoryItem();
48-
if (!queryHistoryItem || queryHistoryItem.t !== "variant-analysis") {
49-
throw new Error(
50-
"No variant analysis results currently open. To open results, click an item in the query history view.",
51-
);
52-
}
53-
54-
await variantAnalysisManager.exportResults(
55-
queryHistoryItem.variantAnalysis.id,
56-
);
57-
}
58-
5939
const MAX_VARIANT_ANALYSIS_EXPORT_PROGRESS_STEPS = 2;
6040

6141
/**

0 commit comments

Comments
 (0)