Skip to content

Commit bb16454

Browse files
committed
Only show 'view SARIF' if SARIF exists.
1 parent 70529a8 commit bb16454

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

extensions/ql-vscode/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@
395395
{
396396
"command": "codeQLQueryHistory.viewSarif",
397397
"group": "9_qlCommands",
398-
"when": "view == codeQLQueryHistory"
398+
"when": "view == codeQLQueryHistory && viewItem == interpretedResultsItem"
399399
},
400400
{
401401
"command": "codeQLTests.showOutputDifferences",

extensions/ql-vscode/src/interface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ export class InterfaceManager extends DisposableObject {
440440
): Promise<Interpretation | undefined> {
441441
let interpretation: Interpretation | undefined = undefined;
442442
if (
443-
(await query.hasInterpretedResults()) &&
443+
(await query.canHaveInterpretedResults()) &&
444444
query.quickEvalPosition === undefined // never do results interpretation if quickEval
445445
) {
446446
try {

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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 = element.query.hasInterpretedResults() ? 'interpretedResultsItem' : 'rawResultsItem';
90+
8691
if (!element.didRunSuccessfully) {
8792
it.iconPath = path.join(this.ctx.extensionPath, FAILED_QUERY_HISTORY_ITEM_ICON);
8893
}
@@ -259,7 +264,7 @@ export class QueryHistoryManager {
259264

260265
async handleViewSarif(queryHistoryItem: CompletedQuery) {
261266
try {
262-
const hasInterpretedResults = await queryHistoryItem.query.hasInterpretedResults();
267+
const hasInterpretedResults = await queryHistoryItem.query.canHaveInterpretedResults();
263268
if (hasInterpretedResults) {
264269
const textDocument = await vscode.workspace.openTextDocument(vscode.Uri.file(queryHistoryItem.query.resultsPaths.interpretedResultsPath));
265270
await vscode.window.showTextDocument(textDocument, vscode.ViewColumn.One);

extensions/ql-vscode/src/run-queries.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,22 @@ export class QueryInfo {
157157
}
158158

159159
/**
160-
* Holds if this query should produce interpreted results.
160+
* Holds if this query can in principle produce interpreted results.
161161
*/
162-
async hasInterpretedResults(): Promise<boolean> {
162+
async canHaveInterpretedResults(): Promise<boolean> {
163163
const hasMetadataFile = await this.dbItem.hasMetadataFile();
164164
if (!hasMetadataFile) {
165165
logger.log("Cannot produce interpreted results since the database does not have a .dbinfo or codeql-database.yml file.");
166166
}
167167
return hasMetadataFile;
168168
}
169+
170+
/**
171+
* Holds if this query actually has produced interpreted results.
172+
*/
173+
hasInterpretedResults(): boolean {
174+
return fs.existsSync(this.resultsPaths.interpretedResultsPath);
175+
}
169176
}
170177

171178
export interface QueryWithResults {

0 commit comments

Comments
 (0)