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

Commit 9409eb0

Browse files
committed
remove commands, call hierarchy rebase
1 parent b4017ea commit 9409eb0

File tree

4 files changed

+101
-57
lines changed

4 files changed

+101
-57
lines changed

package.json

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"Programming Languages"
2020
],
2121
"activationEvents": [
22-
"onCommand:references-view.find",
22+
"onCommand:references-view.findReferences",
2323
"onCommand:references-view.findImplementations",
2424
"onCommand:references-view.showCallHierarchy",
2525
"onCommand:editor.action.showReferences",
@@ -65,7 +65,7 @@
6565
},
6666
"commands": [
6767
{
68-
"command": "references-view.find",
68+
"command": "references-view.findReferences",
6969
"title": "Find All References",
7070
"category": "References"
7171
},
@@ -98,7 +98,7 @@
9898
"category": "References"
9999
},
100100
{
101-
"command": "references-view.remove",
101+
"command": "references-view.removeReferenceItem",
102102
"title": "Dismiss",
103103
"icon": "$(close)"
104104
},
@@ -136,6 +136,11 @@
136136
"category": "Calls",
137137
"icon": "$(call-incoming)"
138138
},
139+
{
140+
"command": "references-view.removeCallItem",
141+
"title": "Dismiss",
142+
"icon": "$(close)"
143+
},
139144
{
140145
"command": "references-view.next",
141146
"title": "Go to Next Reference",
@@ -150,7 +155,7 @@
150155
"menus": {
151156
"editor/context": [
152157
{
153-
"command": "references-view.find",
158+
"command": "references-view.findReferences",
154159
"when": "editorHasReferenceProvider",
155160
"group": "0_navigation@1"
156161
},
@@ -194,19 +199,29 @@
194199
],
195200
"view/item/context": [
196201
{
197-
"command": "references-view.remove",
202+
"command": "references-view.removeReferenceItem",
198203
"group": "inline",
199-
"when": "view == references-view.tree && viewItem == file-item || view == references-view.tree && viewItem == reference-item || view == references-view.tree && viewItem == call-item"
204+
"when": "view == references-view.tree && viewItem == file-item || view == references-view.tree && viewItem == reference-item"
205+
},
206+
{
207+
"command": "references-view.removeCallItem",
208+
"group": "inline",
209+
"when": "view == references-view.tree && viewItem == call-item"
200210
},
201211
{
202212
"command": "references-view.refind",
203213
"group": "inline",
204214
"when": "view == references-view.tree && viewItem == history-item"
205215
},
206216
{
207-
"command": "references-view.remove",
217+
"command": "references-view.removeReferenceItem",
208218
"group": "1",
209-
"when": "view == references-view.tree && viewItem == file-item || view == references-view.tree && viewItem == reference-item || view == references-view.tree && viewItem == call-item"
219+
"when": "view == references-view.tree && viewItem == file-item || view == references-view.tree && viewItem == reference-item"
220+
},
221+
{
222+
"command": "references-view.removeCallItem",
223+
"group": "1",
224+
"when": "view == references-view.tree && viewItem == call-item"
210225
},
211226
{
212227
"command": "references-view.refind",
@@ -228,16 +243,6 @@
228243
"group": "2@3",
229244
"when": "view == references-view.tree && viewItem == file-item || view == references-view.tree && viewItem == reference-item"
230245
},
231-
{
232-
"command": "references-view.showOutgoingCalls",
233-
"group": "inline",
234-
"when": "view == references-view.tree && viewItem == call-item && references-view.callHierarchyMode == showOutgoing"
235-
},
236-
{
237-
"command": "references-view.showIncomingCalls",
238-
"group": "inline",
239-
"when": "view == references-view.tree && viewItem == call-item && references-view.callHierarchyMode == showIncoming"
240-
},
241246
{
242247
"command": "references-view.showOutgoingCalls",
243248
"group": "1",
@@ -251,7 +256,11 @@
251256
],
252257
"commandPalette": [
253258
{
254-
"command": "references-view.remove",
259+
"command": "references-view.removeReferenceItem",
260+
"when": "never"
261+
},
262+
{
263+
"command": "references-view.removeCallItem",
255264
"when": "never"
256265
},
257266
{
@@ -271,7 +280,7 @@
271280
"when": "never"
272281
},
273282
{
274-
"command": "references-view.find",
283+
"command": "references-view.findReferences",
275284
"when": "editorHasReferenceProvider"
276285
},
277286
{
@@ -302,7 +311,7 @@
302311
},
303312
"keybindings": [
304313
{
305-
"command": "references-view.find",
314+
"command": "references-view.findReferences",
306315
"when": "editorHasReferenceProvider",
307316
"key": "shift+alt+f12"
308317
},

src/calls/index.ts

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,45 @@ export function register(tree: SymbolsTree, context: vscode.ExtensionContext): v
1919
}
2020
};
2121

22-
function setCallsDirection(value: CallsDirection) {
22+
function setCallsDirection(value: CallsDirection, anchor: CallItem | unknown) {
2323
direction.value = value;
24-
const input = tree.getInput();
25-
if (input instanceof CallsTreeInput) {
26-
const newInput = new CallsTreeInput(input.uri, input.position, direction.value);
24+
25+
let newInput: CallsTreeInput | undefined;
26+
const oldInput = tree.getInput();
27+
if (anchor instanceof CallItem) {
28+
newInput = new CallsTreeInput(anchor.item.uri, anchor.item.range.start, direction.value);
29+
} else if (oldInput instanceof CallsTreeInput) {
30+
newInput = new CallsTreeInput(oldInput.uri, oldInput.position, direction.value);
31+
}
32+
if (newInput) {
2733
tree.setInput(newInput);
2834
}
2935
}
3036

3137
context.subscriptions.push(
32-
vscode.commands.registerCommand('references-view.showCallHierarchy', () => showCallHierarchy()),
33-
vscode.commands.registerCommand('references-view.showOutgoingCalls', () => setCallsDirection(CallsDirection.Outgoing)),
34-
vscode.commands.registerCommand('references-view.showIncomingCalls', () => setCallsDirection(CallsDirection.Incoming)),
35-
vscode.commands.registerCommand('references-view.showCallItem', (item, preserveFocus?: boolean) => {
36-
if (item instanceof CallItem) {
37-
return vscode.commands.executeCommand('vscode.open', item.item.uri, {
38-
selection: new vscode.Range(item.item.selectionRange.start, item.item.selectionRange.start),
39-
preserveFocus
40-
});
41-
}
42-
})
38+
vscode.commands.registerCommand('references-view.showCallHierarchy', showCallHierarchy),
39+
vscode.commands.registerCommand('references-view.showOutgoingCalls', (item: CallItem | unknown) => setCallsDirection(CallsDirection.Outgoing, item)),
40+
vscode.commands.registerCommand('references-view.showIncomingCalls', (item: CallItem | unknown) => setCallsDirection(CallsDirection.Incoming, item)),
41+
vscode.commands.registerCommand('references-view.showCallItem', showCallItem),
42+
vscode.commands.registerCommand('references-view.removeCallItem', removeCallItem)
4343
);
4444
}
4545

46+
async function showCallItem(item: CallItem | unknown, preserveFocus: boolean = false) {
47+
if (item instanceof CallItem) {
48+
await vscode.commands.executeCommand('vscode.open', item.item.uri, {
49+
selection: new vscode.Range(item.item.selectionRange.start, item.item.selectionRange.start),
50+
preserveFocus
51+
});
52+
}
53+
}
54+
55+
function removeCallItem(item: CallItem | unknown): void {
56+
if (item instanceof CallItem) {
57+
item.remove();
58+
}
59+
}
60+
4661
class RichCallsDirection {
4762

4863
private static _key = 'references-view.callHierarchyMode';

src/calls/model.ts

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class CallsTreeInput implements SymbolTreeInput {
3333

3434
return <SymbolTreeModel>{
3535
provider,
36-
message: undefined,
36+
get message() { return model.roots.length === 0 ? 'No results.' : undefined; },
3737
empty: model.roots.length === 0,
3838
navigation: model,
3939
highlights: model,
@@ -61,10 +61,15 @@ export class CallItem {
6161
children?: CallItem[];
6262

6363
constructor(
64+
private readonly _model: CallsModel,
6465
readonly item: vscode.CallHierarchyItem,
6566
readonly parent: CallItem | undefined,
6667
readonly locations: vscode.Location[] | undefined
6768
) { }
69+
70+
remove(): void {
71+
this._model.remove(this);
72+
}
6873
}
6974

7075
class CallsModel implements SymbolItemNavigation<CallItem>, SymbolItemEditorHighlights<CallItem> {
@@ -77,16 +82,16 @@ class CallsModel implements SymbolItemNavigation<CallItem>, SymbolItemEditorHigh
7782
readonly onDidChange = this._onDidChange.event;
7883

7984
constructor(readonly direction: CallsDirection, items: vscode.CallHierarchyItem[]) {
80-
this.roots = items.map(item => new CallItem(item, undefined, undefined));
85+
this.roots = items.map(item => new CallItem(this, item, undefined, undefined));
8186
}
8287

8388
private async _resolveCalls(call: CallItem): Promise<CallItem[]> {
8489
if (this.direction === CallsDirection.Incoming) {
8590
const calls = await vscode.commands.executeCommand<vscode.CallHierarchyIncomingCall[]>('vscode.provideIncomingCalls', call.item);
86-
return calls ? calls.map(item => new CallItem(item.from, call, item.fromRanges.map(range => new vscode.Location(item.from.uri, range)))) : [];
91+
return calls ? calls.map(item => new CallItem(this, item.from, call, item.fromRanges.map(range => new vscode.Location(item.from.uri, range)))) : [];
8792
} else {
8893
const calls = await vscode.commands.executeCommand<vscode.CallHierarchyOutgoingCall[]>('vscode.provideOutgoingCalls', call.item);
89-
return calls ? calls.map(item => new CallItem(item.to, call, item.fromRanges.map(range => new vscode.Location(call.item.uri, range)))) : [];
94+
return calls ? calls.map(item => new CallItem(this, item.to, call, item.fromRanges.map(range => new vscode.Location(call.item.uri, range)))) : [];
9095
}
9196
}
9297

@@ -97,6 +102,8 @@ class CallsModel implements SymbolItemNavigation<CallItem>, SymbolItemEditorHigh
97102
return call.children;
98103
}
99104

105+
// -- navigation
106+
100107
location(item: CallItem) {
101108
return new vscode.Location(item.item.uri, item.item.range);
102109
}
@@ -125,6 +132,14 @@ class CallsModel implements SymbolItemNavigation<CallItem>, SymbolItemEditorHigh
125132
}
126133
}
127134

135+
// --- highlights
136+
137+
getEditorHighlights(item: CallItem, uri: vscode.Uri): vscode.Range[] | undefined {
138+
return item.locations
139+
?.filter(loc => loc.uri.toString() === uri.toString())
140+
.map(loc => loc.range);
141+
}
142+
128143
remove(item: CallItem) {
129144
const isInRoot = this.roots.includes(item);
130145
const siblings = isInRoot ? this.roots : item.parent?.children;
@@ -133,12 +148,6 @@ class CallsModel implements SymbolItemNavigation<CallItem>, SymbolItemEditorHigh
133148
this._onDidChange.fire(this);
134149
}
135150
}
136-
137-
getEditorHighlights(item: CallItem, uri: vscode.Uri): vscode.Range[] | undefined {
138-
return item.locations
139-
?.filter(loc => loc.uri.toString() === uri.toString())
140-
.map(loc => loc.range);
141-
}
142151
}
143152

144153
class CallItemDataProvider implements vscode.TreeDataProvider<CallItem> {

src/locations/index.ts

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,9 @@ export function register(tree: SymbolsTree, context: vscode.ExtensionContext): v
2020
vscode.commands.registerCommand('references-view.findReferences', () => findLocations('References', 'vscode.executeReferenceProvider')),
2121
vscode.commands.registerCommand('references-view.findImplementations', () => findLocations('Implementations', 'vscode.executeImplementationProvider')),
2222
// --- legacy name
23-
vscode.commands.registerCommand('references-view.find', function () { return vscode.commands.executeCommand('references-view.findReferences', ...arguments); }),
24-
vscode.commands.registerCommand('references-view.showReferenceItem', (item, preserveFocus?: boolean) => {
25-
if (item instanceof ReferenceItem) {
26-
return vscode.commands.executeCommand('vscode.open', item.location.uri, {
27-
selection: new vscode.Range(item.location.range.start, item.location.range.start),
28-
preserveFocus
29-
});
30-
}
31-
}),
23+
vscode.commands.registerCommand('references-view.find', (...args: any[]) => vscode.commands.executeCommand('references-view.findReferences', ...args)),
24+
vscode.commands.registerCommand('references-view.showReferenceItem', showReferenceItem),
25+
vscode.commands.registerCommand('references-view.removeReferenceItem', removeReferenceItem),
3226
vscode.commands.registerCommand('references-view.copy', copyCommand),
3327
vscode.commands.registerCommand('references-view.copyAll', copyAllCommand),
3428
vscode.commands.registerCommand('references-view.copyPath', copyPathCommand),
@@ -43,7 +37,24 @@ const copyAllCommand = async (item: ReferenceItem | FileItem | unknown) => {
4337
}
4438
};
4539

46-
const copyCommand = async (item: LocationsModel | ReferenceItem | FileItem | unknown) => {
40+
function showReferenceItem(item: ReferenceItem | unknown, preserveFocus: boolean = false) {
41+
if (item instanceof ReferenceItem) {
42+
return vscode.commands.executeCommand('vscode.open', item.location.uri, {
43+
selection: new vscode.Range(item.location.range.start, item.location.range.start),
44+
preserveFocus
45+
});
46+
}
47+
}
48+
function removeReferenceItem(item: FileItem | ReferenceItem | unknown) {
49+
if (item instanceof FileItem) {
50+
item.remove();
51+
} else if (item instanceof ReferenceItem) {
52+
item.remove();
53+
}
54+
}
55+
56+
57+
async function copyCommand(item: LocationsModel | ReferenceItem | FileItem | unknown) {
4758
let val: string | undefined;
4859
if (item instanceof LocationsModel) {
4960
val = await item.asCopyText();
@@ -57,7 +68,7 @@ const copyCommand = async (item: LocationsModel | ReferenceItem | FileItem | unk
5768
}
5869
};
5970

60-
const copyPathCommand = (item: FileItem | unknown) => {
71+
async function copyPathCommand(item: FileItem | unknown) {
6172
if (item instanceof FileItem) {
6273
if (item.uri.scheme === 'file') {
6374
vscode.env.clipboard.writeText(item.uri.fsPath);

0 commit comments

Comments
 (0)