Skip to content

Commit afc641b

Browse files
committed
[A] context menu for the outline view
- support view references and call hierarchy in the context menu
1 parent 0c36095 commit afc641b

File tree

6 files changed

+90
-3
lines changed

6 files changed

+90
-3
lines changed

package.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,21 @@
588588
"command": "outline-map.workspace.goToLocation",
589589
"title": "%om.cmd.workspace.goToLocation.title%",
590590
"category": "outline-map"
591+
},
592+
{
593+
"command": "outline-map.context.goToLocation",
594+
"title": "%om.cmd.context.goToLocation.title%",
595+
"category": "outline-map"
596+
},
597+
{
598+
"command": "outline-map.context.showReferences",
599+
"title": "%om.cmd.context.showReferences.title%",
600+
"category": "outline-map"
601+
},
602+
{
603+
"command": "outline-map.context.showCallHierarchy",
604+
"title": "%om.cmd.context.showCallHierarchy.title%",
605+
"category": "outline-map"
591606
}
592607
],
593608
"colors": [
@@ -711,6 +726,27 @@
711726
{
712727
"command": "outline-map.workspace.goToLocation",
713728
"when": "false"
729+
},
730+
{
731+
"command": "outline-map.context.goToLocation",
732+
"when": "false"
733+
}
734+
],
735+
"webview/context": [
736+
{
737+
"command": "outline-map.context.goToLocation",
738+
"when": "webviewId == 'outline-map-view' && webviewSection == 'outline-item'",
739+
"group": "navigation@1"
740+
},
741+
{
742+
"command": "outline-map.context.showReferences",
743+
"when": "webviewId == 'outline-map-view' && webviewSection == 'outline-item'",
744+
"group": "navigation@2"
745+
},
746+
{
747+
"command": "outline-map.context.showCallHierarchy",
748+
"when": "webviewId == 'outline-map-view' && webviewSection == 'outline-item'",
749+
"group": "navigation@3"
714750
}
715751
],
716752
"view/title": [

package.nls.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@
5656
"om.cmd.workspace.excludeInWorkspace.title": "Exclude In Workspace",
5757
"om.cmd.workspace.excludeInFolder.title": "Exclude In Folder",
5858
"om.cmd.workspace.excludeGlobally.title": "Exclude Globally",
59-
"om.cmd.workspace.goToLocation.title": "Go To Symbol Location",
59+
"om.cmd.workspace.goToLocation.title": "Go to Symbol Location",
60+
"om.cmd.context.goToLocation.title": "Go to...",
61+
"om.cmd.context.showReferences.title": "Show References",
62+
"om.cmd.context.showCallHierarchy.title": "Show Call Hierarchy",
6063
"om.colors.outlineMap.visibleRangeBackground": "The color of the visible range in the outline.",
6164
"om.colors.outlineMap.focusingItemBackground": "The background color of the focusing item in the outline.",
6265
"om.colors.outlineMap.focusingItemForeground": "The color of the focusing item in the outline.",

package.nls.zh-cn.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@
5757
"om.cmd.workspace.excludeInFolder.title": "在文件夹中排除",
5858
"om.cmd.workspace.excludeGlobally.title": "全局排除",
5959
"om.cmd.workspace.goToLocation.title": "转到符号位置",
60+
"om.cmd.context.goToLocation.title": "转到...",
61+
"om.cmd.context.showReferences.title": "查看引用",
62+
"om.cmd.context.showCallHierarchy.title": "速览调用层次结构",
6063
"om.colors.outlineMap.visibleRangeBackground": "大纲可见范围背景色",
6164
"om.colors.outlineMap.focusingItemBackground": "大纲聚焦项背景色",
6265
"om.colors.outlineMap.focusingItemForeground": "大纲聚焦项前景色",

src/extension/commands.ts

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Memento, Position, Uri, commands } from 'vscode';
1+
import { Memento, Position, Uri, commands, window } from 'vscode';
22
import { OutlineView } from './outline';
33
import { config } from './config';
44
import { ChangeDepthMsg, FocusMsg, PinSMsg, PinStatus, Sortby } from '../common';
@@ -199,4 +199,39 @@ export const WorkspaceCommandList: Command[] = [
199199
name: 'outline-map.workspace.goToLocation',
200200
fn: workspaceGotoLocation,
201201
},
202+
];
203+
204+
// export
205+
const goToLocation = ({pos}: {pos: Position}) => {
206+
const uri = window.activeTextEditor?.document.uri;
207+
commands.executeCommand('editor.action.goToLocations', uri, new Position(pos.line, pos.character), [], 'goto', '');
208+
};
209+
210+
// export
211+
const showReferences = (arg: {pos: Position}) => {
212+
commands.executeCommand('outline-map.context.goToLocation', arg).then(() => {
213+
commands.executeCommand('editor.action.referenceSearch.trigger');
214+
});
215+
};
216+
217+
const showCallHierarchy = (arg: {pos: Position}) => {
218+
commands.executeCommand('outline-map.context.goToLocation', arg).then(() => {
219+
commands.executeCommand('editor.showCallHierarchy');
220+
});
221+
};
222+
223+
224+
export const ContextCommandList: Command[] = [
225+
{
226+
name: 'outline-map.context.goToLocation',
227+
fn: goToLocation,
228+
},
229+
{
230+
name: 'outline-map.context.showReferences',
231+
fn: showReferences,
232+
},
233+
{
234+
name: 'outline-map.context.showCallHierarchy',
235+
fn: showCallHierarchy,
236+
},
202237
];

src/extension/extension.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313

1414
import { OutlineView } from './outline';
1515

16-
import { OutlineViewCommandList, WorkspaceCommandList } from './commands';
16+
import { ContextCommandList, OutlineViewCommandList, WorkspaceCommandList } from './commands';
1717
import { FocusMsg, PinStatus, ScrollMsg, Sortby } from '../common';
1818
import { config } from './config';
1919
import { debounce, throttle } from '../utils';
@@ -50,6 +50,7 @@ export function activate(context: ExtensionContext) {
5050
registerDiagnosticEvent(outlineView),
5151
...OutlineViewCommandList.map(command => commands.registerCommand(command.name, command.fn.bind(null, outlineView, context.globalState))),
5252
...WorkspaceCommandList.map(command => commands.registerCommand(command.name, command.fn.bind(null, workspaceSymbols))),
53+
...ContextCommandList.map(command => commands.registerCommand(command.name, command.fn.bind(null))),
5354
);
5455
}
5556

src/webview/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,15 @@ function renderSymbolNode(symbolNode: SymbolNode, depth = 0): HTMLDivElement {
234234
container.dataset.inview = symbolNode.inView.toString();
235235
container.dataset.focus = symbolNode.focus.toString();
236236
container.dataset.range = JSON.stringify(symbolNode.range);
237+
// container.dataset['vscode-context'] = JSON.stringify({webviewSection: 'outline-item'});
238+
container.setAttribute(
239+
'data-vscode-context',
240+
JSON.stringify({
241+
webviewSection: 'outline-item',
242+
pos: symbolNode.selectionRange.start,
243+
preventDefaultContextMenuItems: true,
244+
})
245+
);
237246
container.classList.toggle('leaf', symbolNode.children.length === 0);
238247
container.style.setProperty('--depth', depth.toString());
239248

0 commit comments

Comments
 (0)