Skip to content

Commit 3633821

Browse files
committed
Update to new hierarchy APIs
1 parent 7379c10 commit 3633821

File tree

6 files changed

+265
-211
lines changed

6 files changed

+265
-211
lines changed

package.json

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,26 @@
2525
"views": {
2626
"explorer": [
2727
{
28-
"id": "cquery.typeHierarchy",
29-
"name": "Type Hierarchy",
30-
"when": "extension.cquery.typeHierarchyVisible"
28+
"id": "cquery.inheritanceHierarchy",
29+
"name": "Inheritance Hierarchy",
30+
"when": "extension.cquery.inheritanceHierarchyVisible"
3131
},
3232
{
33-
"id": "cquery.callTree",
34-
"name": "Call Tree",
35-
"when": "extension.cquery.callTreeVisible"
33+
"id": "cquery.callHierarchy",
34+
"name": "Call Hierarchy",
35+
"when": "extension.cquery.callHierarchyVisible"
3636
}
3737
]
3838
},
3939
"menus": {
4040
"editor/context": [
4141
{
42-
"command": "cquery.typeHierarchy",
42+
"command": "cquery.inheritanceHierarchy",
4343
"when": "resourceLangId == cpp",
4444
"group": "[email protected]"
4545
},
4646
{
47-
"command": "cquery.callTree",
47+
"command": "cquery.callHierarchy",
4848
"when": "resourceLangId == cpp",
4949
"group": "[email protected]"
5050
},
@@ -66,13 +66,13 @@
6666
],
6767
"view/title": [
6868
{
69-
"command": "cquery.closeTypeHierarchy",
70-
"when": "view == cquery.typeHierarchy",
69+
"command": "cquery.closeinheritanceHierarchy",
70+
"when": "view == cquery.inheritanceHierarchy",
7171
"group": "navigation"
7272
},
7373
{
74-
"command": "cquery.closeCallTree",
75-
"when": "view == cquery.callTree",
74+
"command": "cquery.closecallHierarchy",
75+
"when": "view == cquery.callHierarchy",
7676
"group": "navigation"
7777
}
7878
],
@@ -84,11 +84,11 @@
8484
],
8585
"commandPalette": [
8686
{
87-
"command": "cquery.closeTypeHierarchy",
87+
"command": "cquery.closeinheritanceHierarchy",
8888
"when": "false"
8989
},
9090
{
91-
"command": "cquery.closeCallTree",
91+
"command": "cquery.closecallHierarchy",
9292
"when": "false"
9393
},
9494
{
@@ -104,22 +104,22 @@
104104
"command": "cquery.freshenIndex"
105105
},
106106
{
107-
"title": "Type Hierarchy",
107+
"title": "Inheritance Hierarchy",
108108
"category": "cquery",
109-
"command": "cquery.typeHierarchy"
109+
"command": "cquery.inheritanceHierarchy"
110110
},
111111
{
112112
"title": "Close",
113-
"command": "cquery.closeTypeHierarchy"
113+
"command": "cquery.closeinheritanceHierarchy"
114114
},
115115
{
116-
"title": "Call Tree",
116+
"title": "Call Hierarchy",
117117
"category": "cquery",
118-
"command": "cquery.callTree"
118+
"command": "cquery.callHierarchy"
119119
},
120120
{
121121
"title": "Close",
122-
"command": "cquery.closeCallTree"
122+
"command": "cquery.closecallHierarchy"
123123
},
124124
{
125125
"title": "Show Variables",

src/callHierarchy.ts

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import { Event, EventEmitter, Location, TreeDataProvider, TreeItem, TreeItemCollapsibleState } from 'vscode';
2+
import { LanguageClient } from 'vscode-languageclient/lib/main';
3+
import { parseUri } from './extension';
4+
5+
6+
enum CallType {
7+
Normal = 0,
8+
Base = 1,
9+
Derived = 2,
10+
All = 3 // Normal & Base & Derived
11+
}
12+
export class CallHierarchyNode {
13+
// These properties come directly from the language server.
14+
id: any
15+
name: string
16+
location: Location
17+
callType: CallType
18+
19+
// If |numChildren| != |children.length|, then the node has not been expanded
20+
// and is incomplete - we need to send a new request to expand it.
21+
numChildren: number
22+
children: CallHierarchyNode[]
23+
}
24+
25+
export class CallHierarchyProvider implements TreeDataProvider<CallHierarchyNode> {
26+
root: CallHierarchyNode;
27+
28+
constructor(
29+
readonly languageClient: LanguageClient, readonly derivedDark: string,
30+
readonly derivedLight: string, readonly baseDark: string,
31+
readonly baseLight: string) { }
32+
33+
readonly onDidChangeEmitter: EventEmitter<any> = new EventEmitter<any>();
34+
readonly onDidChangeTreeData: Event<any> = this.onDidChangeEmitter.event;
35+
36+
getTreeItem(element: CallHierarchyNode): TreeItem {
37+
let collapseState = TreeItemCollapsibleState.None
38+
if (element.numChildren > 0) {
39+
if (element.children.length > 0)
40+
collapseState = TreeItemCollapsibleState.Expanded;
41+
else
42+
collapseState = TreeItemCollapsibleState.Collapsed;
43+
}
44+
45+
let light = '';
46+
let dark = '';
47+
if (element.callType == CallType.Base) {
48+
light = this.baseLight;
49+
dark = this.baseDark;
50+
} else if (element.callType == CallType.Derived) {
51+
light = this.derivedLight;
52+
dark = this.derivedDark;
53+
}
54+
55+
let label = element.name;
56+
if (element.location) {
57+
let path = parseUri(element.location.uri).path;
58+
let name = path.substr(path.lastIndexOf('/') + 1);
59+
label += ` (${name}:${element.location.range.start.line + 1})`;
60+
}
61+
62+
return {
63+
label: label,
64+
collapsibleState: collapseState,
65+
contextValue: 'cqueryGoto',
66+
command: {
67+
command: 'cquery.hackGotoForTreeView',
68+
title: 'Goto',
69+
arguments: [element, element.numChildren > 0]
70+
},
71+
iconPath: { light: light, dark: dark }
72+
};
73+
}
74+
75+
getChildren(element?: CallHierarchyNode): CallHierarchyNode[] | Thenable<CallHierarchyNode[]> {
76+
if (!this.root)
77+
return [];
78+
if (!element)
79+
return [this.root];
80+
if (element.numChildren == element.children.length)
81+
return element.children;
82+
83+
return this.languageClient
84+
.sendRequest('$cquery/callHierarchy', {
85+
id: element.id,
86+
callee: false,
87+
callType: CallType.All,
88+
detailedName: false,
89+
levels: 1
90+
})
91+
.then((result: CallHierarchyNode) => {
92+
element.children = result.children;
93+
return result.children;
94+
});
95+
}
96+
}

src/callTree.ts

Lines changed: 0 additions & 89 deletions
This file was deleted.

0 commit comments

Comments
 (0)