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

Commit

Permalink
use vscode.open command for references and call hierarchy items, fyi @…
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Nov 10, 2020
1 parent 2be810e commit 7308002
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 21 deletions.
10 changes: 0 additions & 10 deletions src/calls/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,10 @@ export function register(tree: SymbolsTree, context: vscode.ExtensionContext): v
vscode.commands.registerCommand('references-view.showCallHierarchy', showCallHierarchy),
vscode.commands.registerCommand('references-view.showOutgoingCalls', (item: CallItem | unknown) => setCallsDirection(CallsDirection.Outgoing, item)),
vscode.commands.registerCommand('references-view.showIncomingCalls', (item: CallItem | unknown) => setCallsDirection(CallsDirection.Incoming, item)),
vscode.commands.registerCommand('references-view.showCallItem', showCallItem),
vscode.commands.registerCommand('references-view.removeCallItem', removeCallItem)
);
}

async function showCallItem(item: CallItem | unknown, preserveFocus: boolean = false) {
if (item instanceof CallItem) {
await vscode.commands.executeCommand('vscode.open', item.item.uri, {
selection: new vscode.Range(item.item.selectionRange.start, item.item.selectionRange.start),
preserveFocus
});
}
}

function removeCallItem(item: CallItem | unknown): void {
if (item instanceof CallItem) {
item.remove();
Expand Down
12 changes: 11 additions & 1 deletion src/calls/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,17 @@ class CallItemDataProvider implements vscode.TreeDataProvider<CallItem> {
item.description = element.item.detail;
item.contextValue = 'call-item';
item.iconPath = CallItemDataProvider._getThemeIcon(element.item.kind);
item.command = { command: 'references-view.showCallItem', title: 'Open Call', arguments: [element, true] };
item.command = {
command: 'vscode.open',
title: 'Open Call',
arguments: [
element.item.uri,
<vscode.TextDocumentShowOptions>{
selection: element.item.selectionRange.with({ end: element.item.selectionRange.start }),
preserveFocus: true
}
]
};
item.collapsibleState = vscode.TreeItemCollapsibleState.Collapsed;
return item;
}
Expand Down
9 changes: 0 additions & 9 deletions src/references/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export function register(tree: SymbolsTree, context: vscode.ExtensionContext): v
vscode.commands.registerCommand('references-view.findImplementations', () => findLocations('Implementations', 'vscode.executeImplementationProvider')),
// --- legacy name
vscode.commands.registerCommand('references-view.find', (...args: any[]) => vscode.commands.executeCommand('references-view.findReferences', ...args)),
vscode.commands.registerCommand('references-view.showReferenceItem', showReferenceItem),
vscode.commands.registerCommand('references-view.removeReferenceItem', removeReferenceItem),
vscode.commands.registerCommand('references-view.copy', copyCommand),
vscode.commands.registerCommand('references-view.copyAll', copyAllCommand),
Expand Down Expand Up @@ -62,14 +61,6 @@ const copyAllCommand = async (item: ReferenceItem | FileItem | unknown) => {
}
};

function showReferenceItem(item: ReferenceItem | unknown, preserveFocus: boolean = false) {
if (item instanceof ReferenceItem) {
return vscode.commands.executeCommand('vscode.open', item.location.uri, {
selection: new vscode.Range(item.location.range.start, item.location.range.start),
preserveFocus
});
}
}
function removeReferenceItem(item: FileItem | ReferenceItem | unknown) {
if (item instanceof FileItem) {
item.remove();
Expand Down
12 changes: 11 additions & 1 deletion src/references/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,17 @@ class ReferencesTreeDataProvider implements Required<vscode.TreeDataProvider<Fil
const result = new vscode.TreeItem2(label);
result.collapsibleState = vscode.TreeItemCollapsibleState.None;
result.contextValue = 'reference-item';
result.command = { command: 'references-view.showReferenceItem', title: 'Open Reference', arguments: [element, true] };
result.command = {
command: 'vscode.open',
title: 'Open Reference',
arguments: [
element.location.uri,
<vscode.TextDocumentShowOptions>{
selection: range.with({ end: range.start }),
preserveFocus: true
}
]
};
return result;
}
}
Expand Down

0 comments on commit 7308002

Please sign in to comment.