@@ -115,6 +115,21 @@ class HistoryTreeDataProvider implements vscode.TreeDataProvider<QueryHistoryIte
115115 setCurrentItem ( item : QueryHistoryItem ) {
116116 this . current = item ;
117117 }
118+
119+ remove ( item : QueryHistoryItem ) {
120+ if ( this . current === item )
121+ this . current = undefined ;
122+ const index = this . history . findIndex ( i => i === item ) ;
123+ if ( index >= 0 ) {
124+ this . history . splice ( index , 1 ) ;
125+ if ( this . current === undefined && this . history . length > 0 ) {
126+ // Try to keep a current item, near the deleted item if there
127+ // are any available.
128+ this . current = this . history [ Math . min ( index , this . history . length - 1 ) ] ;
129+ }
130+ this . _onDidChangeTreeData . fire ( ) ;
131+ }
132+ }
118133}
119134
120135/**
@@ -130,11 +145,27 @@ export class QueryHistoryManager {
130145 selectedCallback : ( ( item : QueryHistoryItem ) => void ) | undefined ;
131146 lastItemClick : { time : Date , item : QueryHistoryItem } | undefined ;
132147
148+ async invokeCallbackOn ( queryHistoryItem : QueryHistoryItem ) {
149+ if ( this . selectedCallback !== undefined ) {
150+ const sc = this . selectedCallback ;
151+ await sc ( queryHistoryItem ) ;
152+ }
153+ }
154+
133155 async handleOpenQuery ( queryHistoryItem : QueryHistoryItem ) {
134156 const textDocument = await vscode . workspace . openTextDocument ( vscode . Uri . file ( queryHistoryItem . info . query . program . queryPath ) ) ;
135157 await vscode . window . showTextDocument ( textDocument , vscode . ViewColumn . One ) ;
136158 }
137159
160+ async handleRemoveHistoryItem ( queryHistoryItem : QueryHistoryItem ) {
161+ this . treeDataProvider . remove ( queryHistoryItem ) ;
162+ const current = this . treeDataProvider . getCurrent ( ) ;
163+ if ( current !== undefined ) {
164+ this . treeView . reveal ( current ) ;
165+ await this . invokeCallbackOn ( current ) ;
166+ }
167+ }
168+
138169 async handleItemClicked ( queryHistoryItem : QueryHistoryItem ) {
139170 this . treeDataProvider . setCurrentItem ( queryHistoryItem ) ;
140171
@@ -150,10 +181,7 @@ export class QueryHistoryManager {
150181 }
151182 else {
152183 // show results on single click
153- if ( this . selectedCallback !== undefined ) {
154- const sc = this . selectedCallback ;
155- await sc ( queryHistoryItem ) ;
156- }
184+ await this . invokeCallbackOn ( queryHistoryItem ) ;
157185 }
158186 }
159187
@@ -170,6 +198,7 @@ export class QueryHistoryManager {
170198 }
171199 } ) ;
172200 ctx . subscriptions . push ( vscode . commands . registerCommand ( 'codeQLQueryHistory.openQuery' , this . handleOpenQuery ) ) ;
201+ ctx . subscriptions . push ( vscode . commands . registerCommand ( 'codeQLQueryHistory.removeHistoryItem' , this . handleRemoveHistoryItem . bind ( this ) ) ) ;
173202 ctx . subscriptions . push ( vscode . commands . registerCommand ( 'codeQLQueryHistory.itemClicked' , async ( item ) => {
174203 return this . handleItemClicked ( item ) ;
175204 } ) ) ;
0 commit comments