Skip to content

Commit

Permalink
Fix the type hierarchy
Browse files Browse the repository at this point in the history
Signed-off-by: Sheng Chen <sheche@microsoft.com>
  • Loading branch information
jdneo committed Dec 21, 2023
1 parent 1cb8d0c commit bdcc6f3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/typeHierarchy/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { getActiveLanguageClient } from "../extension";
import { LanguageClient } from "vscode-languageclient/node";
import { getRootItem, resolveTypeHierarchy, typeHierarchyDirectionToContextString } from "./util";
import { CancellationToken, commands, workspace } from "vscode";
import { typeHierarchyTree } from "./typeHierarchyTree";

export class TypeHierarchyTreeInput implements SymbolTreeInput<TypeHierarchyItem> {
readonly contextValue: string = "javaTypeHierarchy";
Expand Down Expand Up @@ -132,8 +133,9 @@ class TypeHierarchyTreeDataProvider implements vscode.TreeDataProvider<TypeHiera
vscode.Uri.parse(element.uri), <vscode.TextDocumentShowOptions>{ selection: element.selectionRange }
]
} : undefined;
// workaround: set a specific id to refresh the collapsible state for treeItems, see: https://github.com/microsoft/vscode/issues/114614#issuecomment-763428052
treeItem.id = `${element.data["element"]}${Math.floor(Math.random() * Number.MAX_SAFE_INTEGER)}`;
// Append the trigger item and the direction to make sure that requesting on the same symbol would preserve the collapse state,
// while for different symbol, reset the collapse state.
treeItem.id = `${typeHierarchyTree.getBaseItem()?.data?.["element"]}-${this.model.getDirection()}-${element.data?.["element"]}`;
if (element.expand) {
treeItem.collapsibleState = vscode.TreeItemCollapsibleState.Expanded;
} else if (this.model.getDirection() === TypeHierarchyDirection.children || this.model.getDirection() === TypeHierarchyDirection.both) {
Expand Down
4 changes: 4 additions & 0 deletions src/typeHierarchy/typeHierarchyTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ export class TypeHierarchyTree {
this.api.setInput(input);
}

public getBaseItem() {
return this.baseItem;
}

private async isValidRequestPosition(uri: vscode.Uri, position: vscode.Position) {
const doc = await vscode.workspace.openTextDocument(uri);
let range = doc.getWordRangeAtPosition(position);
Expand Down

0 comments on commit bdcc6f3

Please sign in to comment.