@@ -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