@@ -115,6 +115,21 @@ class HistoryTreeDataProvider implements vscode.TreeDataProvider<QueryHistoryIte
115
115
setCurrentItem ( item : QueryHistoryItem ) {
116
116
this . current = item ;
117
117
}
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
+ }
118
133
}
119
134
120
135
/**
@@ -130,11 +145,27 @@ export class QueryHistoryManager {
130
145
selectedCallback : ( ( item : QueryHistoryItem ) => void ) | undefined ;
131
146
lastItemClick : { time : Date , item : QueryHistoryItem } | undefined ;
132
147
148
+ async invokeCallbackOn ( queryHistoryItem : QueryHistoryItem ) {
149
+ if ( this . selectedCallback !== undefined ) {
150
+ const sc = this . selectedCallback ;
151
+ await sc ( queryHistoryItem ) ;
152
+ }
153
+ }
154
+
133
155
async handleOpenQuery ( queryHistoryItem : QueryHistoryItem ) {
134
156
const textDocument = await vscode . workspace . openTextDocument ( vscode . Uri . file ( queryHistoryItem . info . query . program . queryPath ) ) ;
135
157
await vscode . window . showTextDocument ( textDocument , vscode . ViewColumn . One ) ;
136
158
}
137
159
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
+
138
169
async handleItemClicked ( queryHistoryItem : QueryHistoryItem ) {
139
170
this . treeDataProvider . setCurrentItem ( queryHistoryItem ) ;
140
171
@@ -150,10 +181,7 @@ export class QueryHistoryManager {
150
181
}
151
182
else {
152
183
// 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 ) ;
157
185
}
158
186
}
159
187
@@ -170,6 +198,7 @@ export class QueryHistoryManager {
170
198
}
171
199
} ) ;
172
200
ctx . subscriptions . push ( vscode . commands . registerCommand ( 'codeQLQueryHistory.openQuery' , this . handleOpenQuery ) ) ;
201
+ ctx . subscriptions . push ( vscode . commands . registerCommand ( 'codeQLQueryHistory.removeHistoryItem' , this . handleRemoveHistoryItem . bind ( this ) ) ) ;
173
202
ctx . subscriptions . push ( vscode . commands . registerCommand ( 'codeQLQueryHistory.itemClicked' , async ( item ) => {
174
203
return this . handleItemClicked ( item ) ;
175
204
} ) ) ;
0 commit comments