Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.

Commit d06cdb2

Browse files
committed
simplify inputs
1 parent 8461e30 commit d06cdb2

File tree

6 files changed

+20
-26
lines changed

6 files changed

+20
-26
lines changed

src/api.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ export interface SymbolTreeInput {
3030
readonly title: string;
3131
readonly uri: vscode.Uri;
3232
readonly position: vscode.Position;
33-
readonly hash: string;
3433

3534
resolve(): Promise<SymbolTreeModel>;
3635
with(position: vscode.Position): SymbolTreeInput;

src/calls/model.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ export class CallsTreeInput implements SymbolTreeInput {
1212

1313
readonly title: string;
1414
readonly contextValue: string = 'callHierarchy';
15-
readonly hash: string;
1615

1716
constructor(
1817
readonly uri: vscode.Uri,
@@ -22,7 +21,6 @@ export class CallsTreeInput implements SymbolTreeInput {
2221
this.title = direction === CallsDirection.Incoming
2322
? 'Callers Of'
2423
: 'Calls From';
25-
this.hash = JSON.stringify([this.uri, this.position, this.direction]);
2624
}
2725

2826
async resolve() {

src/extension.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ function activate2(context: vscode.ExtensionContext) {
170170

171171
const refindCommand = (item: HistoryItem) => {
172172
if (item instanceof HistoryItem) {
173-
vscode.commands.executeCommand(item.commandId, ...[...item.extraArgs, item.uri, item.anchor.getPosition()]);
173+
vscode.commands.executeCommand(item.commandId, ...[...item.extraArgs, item.uri, item.anchor.guessedTrackedPosition()]);
174174
}
175175
};
176176

@@ -250,7 +250,7 @@ function activate2(context: vscode.ExtensionContext) {
250250

251251
} else if (arg instanceof HistoryItem) {
252252
uri = arg.uri;
253-
pos = arg.anchor.getPosition();
253+
pos = arg.anchor.guessedTrackedPosition();
254254
preserveFocus = false;
255255
}
256256

src/history.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class WordAnchor {
2121
return range && doc.getText(range);
2222
}
2323

24-
getPosition(): vscode.Position | undefined {
24+
guessedTrackedPosition(): vscode.Position | undefined {
2525
// funky entry
2626
if (!this._word) {
2727
return this._position;

src/locations/model.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { del, getPreviewChunks, prefixLen, tail } from '../utils';
1010
export class LocationTreeInput implements SymbolTreeInput {
1111

1212
readonly contextValue: string;
13-
readonly hash: string;
1413

1514
constructor(
1615
readonly title: string,
@@ -19,7 +18,6 @@ export class LocationTreeInput implements SymbolTreeInput {
1918
private readonly _command: string,
2019
) {
2120
this.contextValue = _command;
22-
this.hash = JSON.stringify([this.uri, this.position, this._command]);
2321
}
2422

2523
async resolve() {

src/tree.ts

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)