@@ -193,6 +193,7 @@ class HistoryItem {
193193 readonly description : string ;
194194
195195 constructor (
196+ readonly key : string ,
196197 readonly word : string ,
197198 readonly anchor : WordAnchor ,
198199 readonly input : SymbolTreeInput ,
@@ -208,7 +209,7 @@ class TreeInputHistory implements vscode.TreeDataProvider<HistoryItem>{
208209
209210 private readonly _disposables : vscode . Disposable [ ] = [ ] ;
210211 private readonly _ctxHasHistory = new ContextKey < boolean > ( 'reference-list.hasHistory' ) ;
211- private readonly _inputs = new Map < string , Thenable < HistoryItem > > ( ) ;
212+ private readonly _inputs = new Map < string , HistoryItem > ( ) ;
212213
213214 constructor ( private readonly _tree : SymbolsTree ) {
214215
@@ -223,16 +224,15 @@ class TreeInputHistory implements vscode.TreeDataProvider<HistoryItem>{
223224 this . _reRunHistoryItem ( item ) ;
224225 }
225226 } ) ,
226- vscode . commands . registerCommand ( 'references-view.refresh' , async ( ) => {
227- const input = this . _tree . getInput ( ) ;
228- const item = this . _inputs . get ( input ?. hash ?? '' ) ;
227+ vscode . commands . registerCommand ( 'references-view.refresh' , ( ) => {
228+ const [ item ] = this . _inputs . values ( ) ;
229229 if ( item ) {
230- this . _reRunHistoryItem ( await item ) ;
230+ this . _reRunHistoryItem ( item ) ;
231231 }
232232 } ) ,
233233 vscode . commands . registerCommand ( '_references-view.showHistoryItem' , ( item ) => {
234234 if ( item instanceof HistoryItem ) {
235- const position = item . anchor . getPosition ( ) ?? item . input . position ;
235+ const position = item . anchor . guessedTrackedPosition ( ) ?? item . input . position ;
236236 return vscode . commands . executeCommand ( 'vscode.open' , item . input . uri , { selection : new vscode . Range ( position , position ) } ) ;
237237 }
238238 } ) ,
@@ -260,24 +260,23 @@ class TreeInputHistory implements vscode.TreeDataProvider<HistoryItem>{
260260 }
261261
262262 private _reRunHistoryItem ( item : HistoryItem ) : void {
263- this . _inputs . delete ( item . input . hash ) ;
264- const newInput = item . input . with ( item . anchor . getPosition ( ) ?? item . input . position ) ;
263+ this . _inputs . delete ( item . key ) ;
264+ const newInput = item . input . with ( item . anchor . guessedTrackedPosition ( ) ?? item . input . position ) ;
265265 this . _tree . setInput ( newInput ) ;
266266 }
267267
268- add ( input : SymbolTreeInput ) : void {
268+ async add ( input : SymbolTreeInput ) {
269269
270- const p = vscode . workspace . openTextDocument ( input . uri ) . then ( doc => {
271- const anchor = new WordAnchor ( doc , input . position ) ;
272- const range = doc . getWordRangeAtPosition ( input . position ) ?? doc . getWordRangeAtPosition ( input . position , / [ ^ \s ] + / ) ;
273- const word = range ? doc . getText ( range ) : '???' ;
274- return new HistoryItem ( word , anchor , input ) ;
275- } ) ;
270+ const doc = await vscode . workspace . openTextDocument ( input . uri ) ;
271+
272+ const anchor = new WordAnchor ( doc , input . position ) ;
273+ const range = doc . getWordRangeAtPosition ( input . position ) ?? doc . getWordRangeAtPosition ( input . position , / [ ^ \s ] + / ) ;
274+ const word = range ? doc . getText ( range ) : '???' ;
276275
276+ const item = new HistoryItem ( JSON . stringify ( [ range ?. start ?? input . position , input . uri , input . title ] ) , word , anchor , input ) ;
277277 // use filo-ordering of native maps
278- const key = input . hash ;
279- this . _inputs . delete ( key ) ;
280- this . _inputs . set ( key , p ) ;
278+ this . _inputs . delete ( item . key ) ;
279+ this . _inputs . set ( item . key , item ) ;
281280 this . _ctxHasHistory . set ( true ) ;
282281 }
283282
0 commit comments