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

Commit 6a47cb1

Browse files
committed
1 parent 4fd1c75 commit 6a47cb1

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

src/references/index.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,31 @@ export function register(tree: SymbolsTree, context: vscode.ExtensionContext): v
2727
vscode.commands.registerCommand('references-view.copyAll', copyAllCommand),
2828
vscode.commands.registerCommand('references-view.copyPath', copyPathCommand),
2929
);
30+
31+
32+
// --- references.preferredLocation setting
33+
34+
let showReferencesDisposable: vscode.Disposable | undefined;
35+
const config = 'references.preferredLocation';
36+
function updateShowReferences(event?: vscode.ConfigurationChangeEvent) {
37+
if (event && !event.affectsConfiguration(config)) {
38+
return;
39+
}
40+
const value = vscode.workspace.getConfiguration().get<string>(config);
41+
42+
showReferencesDisposable?.dispose();
43+
showReferencesDisposable = undefined;
44+
45+
if (value === 'view') {
46+
showReferencesDisposable = vscode.commands.registerCommand('editor.action.showReferences', async (uri: vscode.Uri, position: vscode.Position, locations: vscode.Location[]) => {
47+
const input = new ReferencesTreeInput('References', new vscode.Location(uri, position), 'vscode.executeReferenceProvider', locations);
48+
tree.setInput(input);
49+
});
50+
}
51+
};
52+
context.subscriptions.push(vscode.workspace.onDidChangeConfiguration(updateShowReferences));
53+
context.subscriptions.push({ dispose: () => showReferencesDisposable?.dispose() });
54+
updateShowReferences();
3055
}
3156

3257
const copyAllCommand = async (item: ReferenceItem | FileItem | unknown) => {

src/references/model.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,27 @@ export class ReferencesTreeInput implements SymbolTreeInput<FileItem | Reference
1515
readonly title: string,
1616
readonly location: vscode.Location,
1717
private readonly _command: string,
18+
private readonly _result?: vscode.Location[] | vscode.LocationLink[]
1819
) {
1920
this.contextValue = _command;
2021
}
2122

2223
async resolve() {
2324

24-
const result = Promise.resolve(vscode.commands.executeCommand<vscode.Location[] | vscode.LocationLink[]>(this._command, this.location.uri, this.location.range.start));
25-
const model = new ReferencesModel(await result ?? []);
26-
const provider = new ReferencesTreeDataProvider(model);
25+
let model: ReferencesModel;
26+
if (this._result) {
27+
model = new ReferencesModel(this._result);
28+
} else {
29+
const resut = await Promise.resolve(vscode.commands.executeCommand<vscode.Location[] | vscode.LocationLink[]>(this._command, this.location.uri, this.location.range.start));
30+
model = new ReferencesModel(resut ?? []);
31+
}
2732

2833
if (model.items.length === 0) {
2934
return;
3035
}
3136

37+
const provider = new ReferencesTreeDataProvider(model);
38+
3239
return {
3340
provider,
3441
get message() { return model.message; },

0 commit comments

Comments
 (0)