Skip to content

Commit 62453d1

Browse files
committed
Split commands for exporting results
There was only a single command for exporting variant analysis results, which would either export the selected result or a given result. From the query history, the command was always calculating the exported result, while we can just give a query ID to export. This will create two separate commands for exporting results, one for exporting the selected results (user-visible) and one for exporting a specific remote query result. This will make it easier to add support for exporting variant analysis results. I'm not sure if there will be impact from renaming the command. I expect the only impact to be that the command history might not show the command in the correct place (i.e. it disappears from recently used commands), but please check if that is the only impact.
1 parent 8b360f3 commit 62453d1

File tree

5 files changed

+50
-23
lines changed

5 files changed

+50
-23
lines changed

extensions/ql-vscode/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@
325325
"title": "CodeQL: Run Variant Analysis"
326326
},
327327
{
328-
"command": "codeQL.exportVariantAnalysisResults",
328+
"command": "codeQL.exportSelectedVariantAnalysisResults",
329329
"title": "CodeQL: Export Variant Analysis Results"
330330
},
331331
{
@@ -954,7 +954,7 @@
954954
"when": "config.codeQL.canary && config.codeQL.variantAnalysis.liveResults"
955955
},
956956
{
957-
"command": "codeQL.exportVariantAnalysisResults",
957+
"command": "codeQL.exportSelectedVariantAnalysisResults",
958958
"when": "config.codeQL.canary"
959959
},
960960
{

extensions/ql-vscode/src/extension.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ import { RemoteQueryResult } from './remote-queries/remote-query-result';
9797
import { URLSearchParams } from 'url';
9898
import { handleDownloadPacks, handleInstallPackDependencies } from './packaging';
9999
import { HistoryItemLabelProvider } from './history-item-label-provider';
100-
import { exportRemoteQueryResults } from './remote-queries/export-results';
100+
import { exportRemoteQueryResults, exportSelectedRemoteQueryResults } from './remote-queries/export-results';
101101
import { RemoteQuery } from './remote-queries/remote-query';
102102
import { EvalLogViewer } from './eval-log-viewer';
103103
import { SummaryLanguageSupport } from './log-insights/summary-language-support';
@@ -975,7 +975,13 @@ async function activateWithInstalledDistribution(
975975
}));
976976

977977
ctx.subscriptions.push(
978-
commandRunner('codeQL.exportVariantAnalysisResults', async (queryId?: string) => {
978+
commandRunner('codeQL.exportSelectedVariantAnalysisResults', async () => {
979+
await exportSelectedRemoteQueryResults(qhm);
980+
})
981+
);
982+
983+
ctx.subscriptions.push(
984+
commandRunner('codeQL.exportRemoteQueryResults', async (queryId: string) => {
979985
await exportRemoteQueryResults(qhm, rqm, ctx, queryId);
980986
})
981987
);

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,8 +1263,20 @@ export class QueryHistoryManager extends DisposableObject {
12631263
await commands.executeCommand('codeQL.copyRepoList', finalSingleItem.queryId);
12641264
}
12651265

1266-
async handleExportResults(): Promise<void> {
1267-
await commands.executeCommand('codeQL.exportVariantAnalysisResults');
1266+
async handleExportResults(
1267+
singleItem: QueryHistoryInfo,
1268+
multiSelect: QueryHistoryInfo[],
1269+
): Promise<void> {
1270+
const { finalSingleItem, finalMultiSelect } = this.determineSelection(singleItem, multiSelect);
1271+
1272+
if (!this.assertSingleQuery(finalMultiSelect) || !finalSingleItem) {
1273+
return;
1274+
}
1275+
1276+
// Remote queries only
1277+
if (finalSingleItem.t === 'remote') {
1278+
await commands.executeCommand('codeQL.exportRemoteQueryResults', finalSingleItem.queryId);
1279+
}
12681280
}
12691281

12701282
addQuery(item: QueryHistoryInfo) {

extensions/ql-vscode/src/remote-queries/export-results.ts

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,28 @@ import { RemoteQueriesManager } from './remote-queries-manager';
1212
import { generateMarkdown } from './remote-queries-markdown-generation';
1313
import { RemoteQuery } from './remote-query';
1414
import { AnalysisResults, sumAnalysesResults } from './shared/analysis-result';
15-
import { RemoteQueryHistoryItem } from './remote-query-history-item';
1615
import { pluralize } from '../pure/word';
1716

17+
/**
18+
* Exports the results of the currently-selected remote query.
19+
*/
20+
export async function exportSelectedRemoteQueryResults(queryHistoryManager: QueryHistoryManager): Promise<void> {
21+
const queryHistoryItem = queryHistoryManager.getCurrentQueryHistoryItem();
22+
if (!queryHistoryItem || queryHistoryItem.t === 'local') {
23+
throw new Error('No variant analysis results currently open. To open results, click an item in the query history view.');
24+
}
25+
26+
if (!queryHistoryItem.completed) {
27+
throw new Error('Variant analysis results are not yet available.');
28+
}
29+
30+
if (queryHistoryItem.t === 'remote') {
31+
return commands.executeCommand('codeQL.exportRemoteQueryResults', queryHistoryItem.queryId);
32+
} else {
33+
throw new Error('No variant analysis results currently open. To open results, click an item in the query history view.');
34+
}
35+
}
36+
1837
/**
1938
* Exports the results of the given or currently-selected remote query.
2039
* The user is prompted to select the export format.
@@ -23,22 +42,12 @@ export async function exportRemoteQueryResults(
2342
queryHistoryManager: QueryHistoryManager,
2443
remoteQueriesManager: RemoteQueriesManager,
2544
ctx: ExtensionContext,
26-
queryId?: string,
45+
queryId: string,
2746
): Promise<void> {
28-
let queryHistoryItem: RemoteQueryHistoryItem;
29-
if (queryId) {
30-
const query = queryHistoryManager.getRemoteQueryById(queryId);
31-
if (!query) {
32-
void logger.log(`Could not find query with id ${queryId}`);
33-
throw new Error('There was an error when trying to retrieve variant analysis information');
34-
}
35-
queryHistoryItem = query;
36-
} else {
37-
const query = queryHistoryManager.getCurrentQueryHistoryItem();
38-
if (!query || query.t !== 'remote') {
39-
throw new Error('No variant analysis results currently open. To open results, click an item in the query history view.');
40-
}
41-
queryHistoryItem = query;
47+
const queryHistoryItem = queryHistoryManager.getRemoteQueryById(queryId);
48+
if (!queryHistoryItem) {
49+
void logger.log(`Could not find query with id ${queryId}`);
50+
throw new Error('There was an error when trying to retrieve variant analysis information');
4251
}
4352

4453
if (!queryHistoryItem.completed) {

extensions/ql-vscode/src/remote-queries/remote-queries-view.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ export class RemoteQueriesView extends AbstractWebview<ToRemoteQueriesMessage, F
146146
await this.downloadAllAnalysesResults(msg);
147147
break;
148148
case 'remoteQueryExportResults':
149-
await commands.executeCommand('codeQL.exportVariantAnalysisResults', msg.queryId);
149+
await commands.executeCommand('codeQL.exportRemoteQueryResults', msg.queryId);
150150
break;
151151
default:
152152
assertNever(msg);

0 commit comments

Comments
 (0)