Fix "Export All" not always exporting the correct query

The "Export All" button was always exporting the selected query, while a
different query could be open in a VSCode panel. This will ensure that
the query ID is passed to the export function, so that the correct query
is exported.
This commit is contained in:
Koen Vlaswinkel
2022-09-21 14:24:54 +02:00
parent c9b68caee4
commit 1b6685ef6f
6 changed files with 33 additions and 13 deletions

View File

@@ -915,8 +915,8 @@ async function activateWithInstalledDistribution(
}));
ctx.subscriptions.push(
commandRunner('codeQL.exportVariantAnalysisResults', async () => {
await exportRemoteQueryResults(qhm, rqm, ctx);
commandRunner('codeQL.exportVariantAnalysisResults', async (queryId?: string) => {
await exportRemoteQueryResults(qhm, rqm, ctx, queryId);
})
);

View File

@@ -422,6 +422,7 @@ export interface RemoteQueryDownloadAllAnalysesResultsMessage {
export interface RemoteQueryExportResultsMessage {
t: 'remoteQueryExportResults';
queryId: string;
}
export interface CopyRepoListMessage {

View File

@@ -680,6 +680,10 @@ export class QueryHistoryManager extends DisposableObject {
return this.treeDataProvider.getCurrent();
}
getQueryById(queryId: string): RemoteQueryHistoryItem | undefined {
return this.treeDataProvider.allHistory.find(i => i.t === 'remote' && i.queryId === queryId) as RemoteQueryHistoryItem;
}
async removeDeletedQueries() {
await Promise.all(this.treeDataProvider.allHistory.map(async (item) => {
if (item.t == 'local' && item.completedQuery && !(await fs.pathExists(item.completedQuery?.query.querySaveDir))) {

View File

@@ -15,26 +15,40 @@ import { RemoteQueriesManager } from './remote-queries-manager';
import { generateMarkdown } from './remote-queries-markdown-generation';
import { RemoteQuery } from './remote-query';
import { AnalysisResults, sumAnalysesResults } from './shared/analysis-result';
import { RemoteQueryHistoryItem } from './remote-query-history-item';
/**
* Exports the results of the currently-selected remote query.
* Exports the results of the given or currently-selected remote query.
* The user is prompted to select the export format.
*/
export async function exportRemoteQueryResults(
queryHistoryManager: QueryHistoryManager,
remoteQueriesManager: RemoteQueriesManager,
ctx: ExtensionContext,
queryId?: string,
): Promise<void> {
const queryHistoryItem = queryHistoryManager.getCurrentQueryHistoryItem();
if (!queryHistoryItem || queryHistoryItem.t !== 'remote') {
throw new Error('No variant analysis results currently open. To open results, click an item in the query history view.');
} else if (!queryHistoryItem.completed) {
let queryHistoryItem: RemoteQueryHistoryItem;
if (queryId) {
const query = queryHistoryManager.getQueryById(queryId);
if (!query) {
throw new Error(`Could not find query with id ${queryId}`);
}
queryHistoryItem = query;
} else {
const query = queryHistoryManager.getCurrentQueryHistoryItem();
if (!query || query.t !== 'remote') {
throw new Error('No variant analysis results currently open. To open results, click an item in the query history view.');
}
queryHistoryItem = query;
}
if (!queryHistoryItem.completed) {
throw new Error('Variant analysis results are not yet available.');
}
const queryId = queryHistoryItem.queryId;
void logger.log(`Exporting variant analysis results for query: ${queryId}`);
void logger.log(`Exporting variant analysis results for query: ${queryHistoryItem.queryId}`);
const query = queryHistoryItem.remoteQuery;
const analysesResults = remoteQueriesManager.getAnalysesResults(queryId);
const analysesResults = remoteQueriesManager.getAnalysesResults(queryHistoryItem.queryId);
const gistOption = {
label: '$(ports-open-browser-icon) Create Gist (GitHub)',

View File

@@ -145,7 +145,7 @@ export class RemoteQueriesView extends AbstractWebview<ToRemoteQueriesMessage, F
await this.downloadAllAnalysesResults(msg);
break;
case 'remoteQueryExportResults':
await commands.executeCommand('codeQL.exportVariantAnalysisResults');
await commands.executeCommand('codeQL.exportVariantAnalysisResults', msg.queryId);
break;
default:
assertNever(msg);

View File

@@ -270,9 +270,10 @@ const AnalysesResultsTitle = ({ totalAnalysesResults, totalResults }: { totalAna
return <SectionTitle>{totalAnalysesResults}/{totalResults} results</SectionTitle>;
};
const exportResults = () => {
const exportResults = (queryResult: RemoteQueryResult) => {
vscode.postMessage({
t: 'remoteQueryExportResults',
queryId: queryResult.queryId,
});
};
@@ -362,7 +363,7 @@ const AnalysesResults = ({
totalResults={totalResults} />
</div>
<div>
<VSCodeButton onClick={exportResults}>Export all</VSCodeButton>
<VSCodeButton onClick={() => exportResults(queryResult)}>Export all</VSCodeButton>
</div>
</div>
<AnalysesResultsDescription