Skip to content

Commit 52b8384

Browse files
committed
Allow custom labels in query history
1 parent e056c61 commit 52b8384

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

extensions/ql-vscode/package.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@
178178
{
179179
"command": "codeQLQueryResults.previousPathStep",
180180
"title": "CodeQL: Show Previous Step on Path"
181+
},
182+
{
183+
"command": "codeQLQueryHistory.setLabel",
184+
"title": "Set Label"
181185
}
182186
],
183187
"menus": {
@@ -213,6 +217,11 @@
213217
"command": "codeQLQueryHistory.removeHistoryItem",
214218
"group": "9_qlCommands",
215219
"when": "view == codeQLQueryHistory"
220+
},
221+
{
222+
"command": "codeQLQueryHistory.setLabel",
223+
"group": "9_qlCommands",
224+
"when": "view == codeQLQueryHistory"
216225
}
217226
],
218227
"explorer/context": [
@@ -259,6 +268,10 @@
259268
{
260269
"command": "codeQLQueryHistory.itemClicked",
261270
"when": "false"
271+
},
272+
{
273+
"command": "codeQLQueryHistory.setLabel",
274+
"when": "false"
262275
}
263276
],
264277
"editor/context": [

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

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ export class QueryHistoryItem {
2121
databaseName: string;
2222
info: EvaluationInfo;
2323

24-
constructor(info: EvaluationInfo) {
24+
constructor(
25+
info: EvaluationInfo,
26+
public label?: string, // user-settable label
27+
) {
2528
this.queryName = helpers.getQueryName(info);
2629
this.databaseName = info.database.name;
2730
this.info = info;
@@ -45,6 +48,9 @@ export class QueryHistoryItem {
4548
}
4649

4750
toString(): string {
51+
if (this.label !== undefined)
52+
return this.label;
53+
4854
const { databaseName, queryName, time } = this;
4955
return `[${time}] ${queryName} on ${databaseName} - ${this.statusString}`;
5056
}
@@ -109,7 +115,7 @@ class HistoryTreeDataProvider implements vscode.TreeDataProvider<QueryHistoryIte
109115
push(item: QueryHistoryItem): void {
110116
this.current = item;
111117
this.history.push(item);
112-
this._onDidChangeTreeData.fire();
118+
this.refresh();
113119
}
114120

115121
setCurrentItem(item: QueryHistoryItem) {
@@ -127,9 +133,13 @@ class HistoryTreeDataProvider implements vscode.TreeDataProvider<QueryHistoryIte
127133
// are any available.
128134
this.current = this.history[Math.min(index, this.history.length - 1)];
129135
}
130-
this._onDidChangeTreeData.fire();
136+
this.refresh();
131137
}
132138
}
139+
140+
refresh() {
141+
this._onDidChangeTreeData.fire();
142+
}
133143
}
134144

135145
/**
@@ -166,6 +176,23 @@ export class QueryHistoryManager {
166176
}
167177
}
168178

179+
async handleSetLabel(queryHistoryItem: QueryHistoryItem) {
180+
const response = await vscode.window.showInputBox({
181+
prompt: 'Label: ',
182+
placeHolder: '(use default)',
183+
value: queryHistoryItem.toString(),
184+
});
185+
// undefined response means the user cancelled the dialog; don't change anything
186+
if (response !== undefined) {
187+
if (response === '')
188+
// Interpret empty string response as "go back to using default"
189+
queryHistoryItem.label = undefined;
190+
else
191+
queryHistoryItem.label = response;
192+
this.treeDataProvider.refresh();
193+
}
194+
}
195+
169196
async handleItemClicked(queryHistoryItem: QueryHistoryItem) {
170197
this.treeDataProvider.setCurrentItem(queryHistoryItem);
171198

@@ -199,6 +226,7 @@ export class QueryHistoryManager {
199226
});
200227
ctx.subscriptions.push(vscode.commands.registerCommand('codeQLQueryHistory.openQuery', this.handleOpenQuery));
201228
ctx.subscriptions.push(vscode.commands.registerCommand('codeQLQueryHistory.removeHistoryItem', this.handleRemoveHistoryItem.bind(this)));
229+
ctx.subscriptions.push(vscode.commands.registerCommand('codeQLQueryHistory.setLabel', this.handleSetLabel.bind(this)));
202230
ctx.subscriptions.push(vscode.commands.registerCommand('codeQLQueryHistory.itemClicked', async (item) => {
203231
return this.handleItemClicked(item);
204232
}));

0 commit comments

Comments
 (0)