Skip to content

Commit a8532af

Browse files
committed
Display failure icon next to failed query history items
1 parent 2f848af commit a8532af

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as path from 'path';
12
import * as vscode from 'vscode';
23
import { ExtensionContext, window as Window } from 'vscode';
34
import { EvaluationInfo } from './queries';
@@ -18,6 +19,11 @@ export type QueryHistoryItemOptions = {
1819
queryText?: string, // stored query for quick query
1920
}
2021

22+
/**
23+
* Path to icon to display next to a failed query history item.
24+
*/
25+
const FAILED_QUERY_HISTORY_ITEM_ICON: string = 'media/red-x.svg';
26+
2127
/**
2228
* One item in the user-displayed list of queries that have been run.
2329
*/
@@ -75,6 +81,10 @@ export class QueryHistoryItem {
7581
return this.config.format;
7682
}
7783

84+
get didRunSuccessfully(): boolean {
85+
return this.info.result.resultType === messages.QueryResultType.SUCCESS;
86+
}
87+
7888
toString(): string {
7989
return this.interpolate(this.getLabel());
8090
}
@@ -94,15 +104,16 @@ class HistoryTreeDataProvider implements vscode.TreeDataProvider<QueryHistoryIte
94104
private _onDidChangeTreeData: vscode.EventEmitter<QueryHistoryItem | undefined> = new vscode.EventEmitter<QueryHistoryItem | undefined>();
95105
readonly onDidChangeTreeData: vscode.Event<QueryHistoryItem | undefined> = this._onDidChangeTreeData.event;
96106

107+
private ctx: ExtensionContext;
97108
private history: QueryHistoryItem[] = [];
98109

99110
/**
100111
* When not undefined, must be reference-equal to an item in `this.databases`.
101112
*/
102113
private current: QueryHistoryItem | undefined;
103114

104-
constructor() {
105-
this.history = [];
115+
constructor(ctx: ExtensionContext) {
116+
this.ctx = ctx;
106117
}
107118

108119
getTreeItem(element: QueryHistoryItem): vscode.TreeItem {
@@ -114,6 +125,10 @@ class HistoryTreeDataProvider implements vscode.TreeDataProvider<QueryHistoryIte
114125
arguments: [element],
115126
};
116127

128+
if (!element.didRunSuccessfully) {
129+
it.iconPath = path.join(this.ctx.extensionPath, FAILED_QUERY_HISTORY_ITEM_ICON);
130+
}
131+
117132
return it;
118133
}
119134

@@ -247,7 +262,7 @@ export class QueryHistoryManager {
247262
) {
248263
this.ctx = ctx;
249264
this.selectedCallback = selectedCallback;
250-
const treeDataProvider = this.treeDataProvider = new HistoryTreeDataProvider();
265+
const treeDataProvider = this.treeDataProvider = new HistoryTreeDataProvider(ctx);
251266
this.treeView = Window.createTreeView('codeQLQueryHistory', { treeDataProvider });
252267
// Lazily update the tree view selection due to limitations of TreeView API (see
253268
// `updateTreeViewSelectionIfVisible` doc for details)

0 commit comments

Comments
 (0)