Skip to content

Commit 2fd5f38

Browse files
authored
Merge pull request #1528 from github/koesie10/fix-export-all-selection
Fix "Export All" not always exporting the correct query
2 parents a53c04e + 06d2284 commit 2fd5f38

6 files changed

Lines changed: 34 additions & 13 deletions

File tree

extensions/ql-vscode/src/extension.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -915,8 +915,8 @@ async function activateWithInstalledDistribution(
915915
}));
916916

917917
ctx.subscriptions.push(
918-
commandRunner('codeQL.exportVariantAnalysisResults', async () => {
919-
await exportRemoteQueryResults(qhm, rqm, ctx);
918+
commandRunner('codeQL.exportVariantAnalysisResults', async (queryId?: string) => {
919+
await exportRemoteQueryResults(qhm, rqm, ctx, queryId);
920920
})
921921
);
922922

extensions/ql-vscode/src/pure/interface-types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ export interface RemoteQueryDownloadAllAnalysesResultsMessage {
422422

423423
export interface RemoteQueryExportResultsMessage {
424424
t: 'remoteQueryExportResults';
425+
queryId: string;
425426
}
426427

427428
export interface CopyRepoListMessage {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,10 @@ export class QueryHistoryManager extends DisposableObject {
680680
return this.treeDataProvider.getCurrent();
681681
}
682682

683+
getRemoteQueryById(queryId: string): RemoteQueryHistoryItem | undefined {
684+
return this.treeDataProvider.allHistory.find(i => i.t === 'remote' && i.queryId === queryId) as RemoteQueryHistoryItem;
685+
}
686+
683687
async removeDeletedQueries() {
684688
await Promise.all(this.treeDataProvider.allHistory.map(async (item) => {
685689
if (item.t == 'local' && item.completedQuery && !(await fs.pathExists(item.completedQuery?.query.querySaveDir))) {

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

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,41 @@ import { RemoteQueriesManager } from './remote-queries-manager';
1515
import { generateMarkdown } from './remote-queries-markdown-generation';
1616
import { RemoteQuery } from './remote-query';
1717
import { AnalysisResults, sumAnalysesResults } from './shared/analysis-result';
18+
import { RemoteQueryHistoryItem } from './remote-query-history-item';
1819

1920
/**
20-
* Exports the results of the currently-selected remote query.
21+
* Exports the results of the given or currently-selected remote query.
2122
* The user is prompted to select the export format.
2223
*/
2324
export async function exportRemoteQueryResults(
2425
queryHistoryManager: QueryHistoryManager,
2526
remoteQueriesManager: RemoteQueriesManager,
2627
ctx: ExtensionContext,
28+
queryId?: string,
2729
): Promise<void> {
28-
const queryHistoryItem = queryHistoryManager.getCurrentQueryHistoryItem();
29-
if (!queryHistoryItem || queryHistoryItem.t !== 'remote') {
30-
throw new Error('No variant analysis results currently open. To open results, click an item in the query history view.');
31-
} else if (!queryHistoryItem.completed) {
30+
let queryHistoryItem: RemoteQueryHistoryItem;
31+
if (queryId) {
32+
const query = queryHistoryManager.getRemoteQueryById(queryId);
33+
if (!query) {
34+
void logger.log(`Could not find query with id ${queryId}`);
35+
throw new Error('There was an error when trying to retrieve variant analysis information');
36+
}
37+
queryHistoryItem = query;
38+
} else {
39+
const query = queryHistoryManager.getCurrentQueryHistoryItem();
40+
if (!query || query.t !== 'remote') {
41+
throw new Error('No variant analysis results currently open. To open results, click an item in the query history view.');
42+
}
43+
queryHistoryItem = query;
44+
}
45+
46+
if (!queryHistoryItem.completed) {
3247
throw new Error('Variant analysis results are not yet available.');
3348
}
34-
const queryId = queryHistoryItem.queryId;
35-
void logger.log(`Exporting variant analysis results for query: ${queryId}`);
49+
50+
void logger.log(`Exporting variant analysis results for query: ${queryHistoryItem.queryId}`);
3651
const query = queryHistoryItem.remoteQuery;
37-
const analysesResults = remoteQueriesManager.getAnalysesResults(queryId);
52+
const analysesResults = remoteQueriesManager.getAnalysesResults(queryHistoryItem.queryId);
3853

3954
const gistOption = {
4055
label: '$(ports-open-browser-icon) Create Gist (GitHub)',

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

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

extensions/ql-vscode/src/view/remote-queries/RemoteQueries.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,10 @@ const AnalysesResultsTitle = ({ totalAnalysesResults, totalResults }: { totalAna
270270
return <SectionTitle>{totalAnalysesResults}/{totalResults} results</SectionTitle>;
271271
};
272272

273-
const exportResults = () => {
273+
const exportResults = (queryResult: RemoteQueryResult) => {
274274
vscode.postMessage({
275275
t: 'remoteQueryExportResults',
276+
queryId: queryResult.queryId,
276277
});
277278
};
278279

@@ -362,7 +363,7 @@ const AnalysesResults = ({
362363
totalResults={totalResults} />
363364
</div>
364365
<div>
365-
<VSCodeButton onClick={exportResults}>Export all</VSCodeButton>
366+
<VSCodeButton onClick={() => exportResults(queryResult)}>Export all</VSCodeButton>
366367
</div>
367368
</div>
368369
<AnalysesResultsDescription

0 commit comments

Comments
 (0)