@@ -15,26 +15,41 @@ import { RemoteQueriesManager } from './remote-queries-manager';
1515import { generateMarkdown } from './remote-queries-markdown-generation' ;
1616import { RemoteQuery } from './remote-query' ;
1717import { 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 */
2324export 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)' ,
0 commit comments