Skip to content

Commit 34a3d89

Browse files
committed
Permit computation of method hierarchy through type hierarchy API.
- Method hierarchy needs to pass along the method signature to be searched on each type - Use data field to store the method signature being searched (if any), and the human readable method name - Use SymbolKind.Null to denote a type in the hierarchy that does not implement the given method Signed-off-by: Roland Grunberg <[email protected]>
1 parent de77dc8 commit 34a3d89

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/typeHierarchy/model.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,25 @@ export class TypeHierarchyTreeInput implements SymbolTreeInput<TypeHierarchyItem
1515

1616
constructor(readonly location: vscode.Location, readonly direction: TypeHierarchyDirection, readonly token: CancellationToken, item: TypeHierarchyItem) {
1717
this.baseItem = item;
18+
const isMethodHierarchy: boolean = item.data["method"] !== undefined;
19+
let methodName: string;
20+
if (isMethodHierarchy) {
21+
methodName = item.data["method_name"];
22+
}
1823
switch (direction) {
1924
case TypeHierarchyDirection.both:
20-
this.title = "Class Hierarchy";
25+
this.title = isMethodHierarchy ? `Method Hierarchy for ${methodName}` : "Class Hierarchy";
2126
break;
2227
case TypeHierarchyDirection.parents:
23-
this.title = "Supertype Hierarchy";
28+
this.title = isMethodHierarchy ? `Supertype (Method) Hierarchy for ${methodName}` : "Supertype Hierarchy";
2429
break;
2530
case TypeHierarchyDirection.children:
26-
this.title = "Subtype Hierarchy";
31+
this.title = isMethodHierarchy ? `Subtype (Method) Hierarchy for ${methodName}` : "Subtype Hierarchy";
2732
break;
2833
default:
2934
return;
3035
}
36+
3137
}
3238

3339
async resolve(): Promise<SymbolTreeModel<TypeHierarchyItem>> {
@@ -127,7 +133,7 @@ class TypeHierarchyTreeDataProvider implements vscode.TreeDataProvider<TypeHiera
127133
]
128134
} : undefined;
129135
// workaround: set a specific id to refresh the collapsible state for treeItems, see: https://github.com/microsoft/vscode/issues/114614#issuecomment-763428052
130-
treeItem.id = `${element.data}${Math.floor(Math.random() * Number.MAX_SAFE_INTEGER)}`;
136+
treeItem.id = `${element.data["element"]}${Math.floor(Math.random() * Number.MAX_SAFE_INTEGER)}`;
131137
if (element.expand) {
132138
treeItem.collapsibleState = vscode.TreeItemCollapsibleState.Expanded;
133139
} else if (this.model.getDirection() === TypeHierarchyDirection.children || this.model.getDirection() === TypeHierarchyDirection.both) {

src/typeHierarchy/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export async function getRootItem(client: LanguageClient, typeHierarchyItem: Typ
110110
return typeHierarchyItem;
111111
} else {
112112
for (const parent of typeHierarchyItem.parents) {
113-
if (parent.kind === SymbolKind.Class) {
113+
if (parent.kind === SymbolKind.Class || parent.kind === SymbolKind.Null) {
114114
parent.children = [typeHierarchyItem];
115115
parent.expand = true;
116116
return getRootItem(client, parent, token);

0 commit comments

Comments
 (0)