@@ -74,7 +74,7 @@ class HistoryTreeDataProvider implements vscode.TreeDataProvider<CompletedQuery>
7474 constructor ( private ctx : ExtensionContext ) {
7575 }
7676
77- getTreeItem ( element : CompletedQuery ) : vscode . TreeItem {
77+ async getTreeItem ( element : CompletedQuery ) : Promise < vscode . TreeItem > {
7878 const it = new vscode . TreeItem ( element . toString ( ) ) ;
7979
8080 it . command = {
@@ -83,6 +83,11 @@ class HistoryTreeDataProvider implements vscode.TreeDataProvider<CompletedQuery>
8383 arguments : [ element ] ,
8484 } ;
8585
86+ // Mark this query history item according to whether it has a
87+ // SARIF file so that we can make context menu items conditionally
88+ // available.
89+ it . contextValue = await element . query . hasInterpretedResults ( ) ? 'interpretedResultsItem' : 'rawResultsItem' ;
90+
8691 if ( ! element . didRunSuccessfully ) {
8792 it . iconPath = path . join ( this . ctx . extensionPath , FAILED_QUERY_HISTORY_ITEM_ICON ) ;
8893 }
@@ -257,6 +262,22 @@ export class QueryHistoryManager {
257262 }
258263 }
259264
265+ async handleViewSarif ( queryHistoryItem : CompletedQuery ) {
266+ try {
267+ const hasInterpretedResults = await queryHistoryItem . query . canHaveInterpretedResults ( ) ;
268+ if ( hasInterpretedResults ) {
269+ const textDocument = await vscode . workspace . openTextDocument ( vscode . Uri . file ( queryHistoryItem . query . resultsPaths . interpretedResultsPath ) ) ;
270+ await vscode . window . showTextDocument ( textDocument , vscode . ViewColumn . One ) ;
271+ }
272+ else {
273+ const label = queryHistoryItem . getLabel ( ) ;
274+ helpers . showAndLogInformationMessage ( `Query ${ label } has no interpreted results.` ) ;
275+ }
276+ } catch ( e ) {
277+ helpers . showAndLogErrorMessage ( e . message ) ;
278+ }
279+ }
280+
260281 async getQueryText ( queryHistoryItem : CompletedQuery ) : Promise < string > {
261282 if ( queryHistoryItem . options . queryText ) {
262283 return queryHistoryItem . options . queryText ;
@@ -296,6 +317,7 @@ export class QueryHistoryManager {
296317 ctx . subscriptions . push ( vscode . commands . registerCommand ( 'codeQLQueryHistory.setLabel' , this . handleSetLabel . bind ( this ) ) ) ;
297318 ctx . subscriptions . push ( vscode . commands . registerCommand ( 'codeQLQueryHistory.showQueryLog' , this . handleShowQueryLog . bind ( this ) ) ) ;
298319 ctx . subscriptions . push ( vscode . commands . registerCommand ( 'codeQLQueryHistory.showQueryText' , this . handleShowQueryText . bind ( this ) ) ) ;
320+ ctx . subscriptions . push ( vscode . commands . registerCommand ( 'codeQLQueryHistory.viewSarif' , this . handleViewSarif . bind ( this ) ) ) ;
299321 ctx . subscriptions . push ( vscode . commands . registerCommand ( 'codeQLQueryHistory.itemClicked' , async ( item ) => {
300322 return this . handleItemClicked ( item ) ;
301323 } ) ) ;
0 commit comments