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

Commit 6495852

Browse files
committed
can navigate, dispose model
1 parent e836077 commit 6495852

File tree

7 files changed

+23
-11
lines changed

7 files changed

+23
-11
lines changed

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,13 @@
138138
},
139139
{
140140
"command": "references-view.next",
141-
"title": "Go to Next Reference"
141+
"title": "Go to Next Reference",
142+
"enablement": "references-view.canNavigate"
142143
},
143144
{
144145
"command": "references-view.prev",
145-
"title": "Go to Previous Reference"
146+
"title": "Go to Previous Reference",
147+
"enablement": "references-view.canNavigate"
146148
}
147149
],
148150
"menus": {

src/api.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export interface SymbolTreeModel {
2222
provider: Required<vscode.TreeDataProvider<unknown>>;
2323
navigation?: SymbolItemNavigation<any>;
2424
highlights?: SymbolItemEditorHighlights<any>;
25+
dispose?(): void;
2526
}
2627

2728
export interface SymbolTreeInput {

src/calls/model.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,17 @@ export class CallsTreeInput implements SymbolTreeInput {
2929

3030
const items = await Promise.resolve(vscode.commands.executeCommand<vscode.CallHierarchyItem[]>('vscode.prepareCallHierarchy', this.uri, this.position));
3131
const model = new CallsModel(this.direction, items ?? []);
32+
const provider = new CallItemDataProvider(model);
3233

3334
return <SymbolTreeModel>{
34-
provider: new CallItemDataProvider(model),
35+
provider,
3536
message: undefined,
3637
empty: model.roots.length === 0,
3738
navigation: model,
38-
highlights: model
39+
highlights: model,
40+
dispose() {
41+
provider.dispose();
42+
}
3943
};
4044
}
4145

src/highlights.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class EditorHighlights<T> {
2424
vscode.window.onDidChangeActiveTextEditor(() => _view.visible && this._show()),
2525
_view.onDidChangeVisibility(e => e.visible ? this._show() : this._hide())
2626
);
27-
27+
this._show();
2828
}
2929

3030
dispose() {

src/locations/model.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,17 @@ export class LocationTreeInput implements SymbolTreeInput {
2626

2727
const result = Promise.resolve(vscode.commands.executeCommand<vscode.Location[] | vscode.LocationLink[]>(this._command, this.uri, this.position));
2828
const model = new LocationsModel(await result ?? []);
29+
const provider = new LocationsTreeDataProvider(model);
2930

3031
return <SymbolTreeModel>{
31-
provider: new LocationsTreeDataProvider(model),
32+
provider,
3233
get message() { return model.message; },
3334
empty: model.items.length === 0,
3435
navigation: model,
35-
highlights: model
36+
highlights: model,
37+
dispose(): void {
38+
provider.dispose();
39+
}
3640
};
3741
}
3842

src/navigation.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55

66
import * as vscode from 'vscode';
77
import { SymbolItemNavigation } from './api';
8+
import { ContextKey } from './models';
89

910
export class Navigation {
1011

1112
private readonly _disposables: vscode.Disposable[] = [];
13+
private readonly _ctxCanNavigate = new ContextKey<boolean>('references-view.canNavigate');
1214

1315
private _delegate?: SymbolItemNavigation<unknown>;
1416

@@ -25,6 +27,7 @@ export class Navigation {
2527

2628
update(delegate: SymbolItemNavigation<unknown> | undefined) {
2729
this._delegate = delegate;
30+
this._ctxCanNavigate.set(Boolean(this._delegate));
2831
}
2932

3033
private _anchor(): undefined | unknown {

src/tree.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ export class SymbolsTree {
9292
let highlights: EditorHighlights<unknown> | undefined;
9393
if (model.highlights) {
9494
highlights = new EditorHighlights(this._tree, model.highlights);
95-
highlights.update();
9695
disposables.push(highlights);
9796
}
9897

@@ -102,9 +101,8 @@ export class SymbolsTree {
102101
this._tree.message = model.message;
103102
highlights?.update();
104103
}));
105-
106-
if (typeof ((model.provider as unknown) as vscode.Disposable).dispose === 'function') {
107-
disposables.push((model.provider as unknown) as vscode.Disposable);
104+
if (typeof model.dispose === 'function') {
105+
disposables.push(new vscode.Disposable(() => model.dispose!()));
108106
}
109107
this._sessionDisposable = vscode.Disposable.from(...disposables);
110108
}

0 commit comments

Comments
 (0)