@@ -13,6 +13,11 @@ import { QueryHistoryConfig } from './config';
1313 * `TreeDataProvider` subclass below.
1414 */
1515
16+ export type QueryHistoryItemOptions = {
17+ label ?: string , // user-settable label
18+ queryText ?: string , // stored query for quick query
19+ }
20+
1621/**
1722 * One item in the user-displayed list of queries that have been run.
1823 */
@@ -25,7 +30,7 @@ export class QueryHistoryItem {
2530 constructor (
2631 info : EvaluationInfo ,
2732 public config : QueryHistoryConfig ,
28- public label ?: string , // user-settable label
33+ public options : QueryHistoryItemOptions = info . historyItemOptions ,
2934 ) {
3035 this . queryName = helpers . getQueryName ( info ) ;
3136 this . databaseName = info . database . name ;
@@ -65,8 +70,8 @@ export class QueryHistoryItem {
6570 }
6671
6772 getLabel ( ) : string {
68- if ( this . label !== undefined )
69- return this . label ;
73+ if ( this . options . label !== undefined )
74+ return this . options . label ;
7075 return this . config . format ;
7176 }
7277
@@ -179,9 +184,15 @@ export class QueryHistoryManager {
179184 }
180185 }
181186
182- async handleOpenQuery ( queryHistoryItem : QueryHistoryItem ) {
187+ async handleOpenQuery ( queryHistoryItem : QueryHistoryItem ) : Promise < void > {
183188 const textDocument = await vscode . workspace . openTextDocument ( vscode . Uri . file ( queryHistoryItem . info . query . program . queryPath ) ) ;
184- await vscode . window . showTextDocument ( textDocument , vscode . ViewColumn . One ) ;
189+ const editor = await vscode . window . showTextDocument ( textDocument , vscode . ViewColumn . One ) ;
190+ const queryText = queryHistoryItem . options . queryText ;
191+ if ( queryText !== undefined ) {
192+ await editor . edit ( edit => edit . replace ( textDocument . validateRange (
193+ new vscode . Range ( 0 , 0 , textDocument . lineCount , 0 ) ) , queryText )
194+ ) ;
195+ }
185196 }
186197
187198 async handleRemoveHistoryItem ( queryHistoryItem : QueryHistoryItem ) {
@@ -203,9 +214,9 @@ export class QueryHistoryManager {
203214 if ( response !== undefined ) {
204215 if ( response === '' )
205216 // Interpret empty string response as "go back to using default"
206- queryHistoryItem . label = undefined ;
217+ queryHistoryItem . options . label = undefined ;
207218 else
208- queryHistoryItem . label = response ;
219+ queryHistoryItem . options . label = response ;
209220 this . treeDataProvider . refresh ( ) ;
210221 }
211222 }
@@ -277,7 +288,7 @@ export class QueryHistoryManager {
277288 const current = this . treeDataProvider . getCurrent ( ) ;
278289 if ( current != undefined ) {
279290 // We must fire the onDidChangeTreeData event to ensure the current element can be selected
280- // using `reveal` if the tree view was not visible when the current element was added.
291+ // using `reveal` if the tree view was not visible when the current element was added.
281292 this . treeDataProvider . refresh ( ) ;
282293 this . treeView . reveal ( current ) ;
283294 }
0 commit comments