Repository navigation
Expand file tree
/
Copy pathdocumentSymbolNode.ts
More file actions
74 lines (64 loc) · 2.65 KB
/
Copy pathdocumentSymbolNode.ts
File metadata and controls
74 lines (64 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
import { Command, DocumentSymbol, Range, SymbolKind, ThemeIcon, TreeItem, TreeItemCollapsibleState } from "vscode";
import { Commands } from "../commands";
import { Explorer } from "../constants";
import { ExplorerNode } from "./explorerNode";
import { PrimaryTypeNode } from "./PrimaryTypeNode";
export class DocumentSymbolNode extends ExplorerNode {
private readonly _iconMap: Map<SymbolKind, string> = new Map([
[SymbolKind.Package, "package"],
[SymbolKind.Class, "class"],
[SymbolKind.Interface, "interface"],
[SymbolKind.Enum, "enum"],
[SymbolKind.EnumMember, "enum-member"],
[SymbolKind.Constant, "constant"],
[SymbolKind.Method, "method"],
[SymbolKind.Function, "method"],
[SymbolKind.Constructor, "method"],
[SymbolKind.Field, "field"],
[SymbolKind.Property, "property"],
[SymbolKind.Variable, "variable"],
]);
constructor(private readonly symbolInfo: DocumentSymbol, parent: PrimaryTypeNode) {
super(parent);
}
public getChildren(): ExplorerNode[] | Promise<ExplorerNode[]> {
const res: ExplorerNode[] = [];
if (this.symbolInfo?.children?.length) {
this.symbolInfo.children.forEach((child) => {
res.push(new DocumentSymbolNode(child, this.getParent() as PrimaryTypeNode));
});
}
return res;
}
public getTreeItem(): TreeItem | Promise<TreeItem> {
const item = new TreeItem(this.symbolInfo.name,
this.symbolInfo?.children?.length ? TreeItemCollapsibleState.Collapsed
: TreeItemCollapsibleState.None);
item.iconPath = this.iconPath;
item.command = this.command;
return item;
}
public get range(): Range {
// Using `selectionRange` instead of `range` to make sure the cursor will be pointing to the codes, not the comments
return this.symbolInfo.selectionRange;
}
public computeContextValue(): string | undefined {
return `java:${Explorer.ContextValueType.Symbol}`;
}
protected get iconPath(): ThemeIcon {
if (this._iconMap.has(this.symbolInfo.kind)) {
const symbolKind = this._iconMap.get(this.symbolInfo.kind);
return new ThemeIcon(`symbol-${symbolKind}`);
}
return new ThemeIcon("symbol-misc");
}
protected get command(): Command {
return {
title: "Go to outline",
command: Commands.VIEW_PACKAGE_OUTLINE,
arguments: [(this.getParent() as PrimaryTypeNode).uri, this.range],
};
}
}