forked from microsoft/vscode-java-dependency
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrimaryTypeNode.ts
More file actions
112 lines (97 loc) · 3.97 KB
/
Copy pathPrimaryTypeNode.ts
File metadata and controls
112 lines (97 loc) · 3.97 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
import { Command, commands, DocumentSymbol, SymbolInformation, SymbolKind, TextDocument, ThemeIcon, Uri, workspace } from "vscode";
import { createUuid, sendOperationEnd, sendOperationStart } from "vscode-extension-telemetry-wrapper";
import { Commands } from "../commands";
import { Explorer } from "../constants";
import { INodeData, TypeKind } from "../java/nodeData";
import { Settings } from "../settings";
import { isTest } from "../utility";
import { DataNode } from "./dataNode";
import { DocumentSymbolNode } from "./documentSymbolNode";
import { ExplorerNode } from "./explorerNode";
export class PrimaryTypeNode extends DataNode {
public static K_TYPE_KIND = "TypeKind";
constructor(nodeData: INodeData, parent: DataNode, protected _rootNode?: DataNode) {
super(nodeData, parent);
}
protected async loadData(): Promise<SymbolInformation[] | DocumentSymbol[] | undefined> {
if (!this.hasChildren() || !this.nodeData.uri) {
return undefined;
}
return workspace.openTextDocument(Uri.parse(this.nodeData.uri)).then((doc) => {
return this.getSymbols(doc);
});
}
protected createChildNodeList(): ExplorerNode[] {
const result: ExplorerNode[] = [];
if (this.nodeData.children && this.nodeData.children.length) {
for (const child of this.nodeData.children) {
const documentSymbol: DocumentSymbol = child as DocumentSymbol;
// Do not show the package declaration
if (documentSymbol.kind === SymbolKind.Package) {
continue;
}
if (documentSymbol.name === this.nodeData.name) {
for (const childSymbol of documentSymbol.children) {
result.push(new DocumentSymbolNode(childSymbol, this));
}
}
}
}
return result;
}
protected get iconPath(): string | ThemeIcon {
switch (this.nodeData.metaData?.[PrimaryTypeNode.K_TYPE_KIND]) {
case TypeKind.Enum:
return new ThemeIcon("symbol-enum");
case TypeKind.Interface:
return new ThemeIcon("symbol-interface");
default:
return new ThemeIcon("symbol-class");
}
}
protected hasChildren(): boolean {
return Settings.showMembers();
}
private async getSymbols(document: TextDocument): Promise<SymbolInformation[] | DocumentSymbol[] | undefined> {
let error;
const operationId = createUuid();
const startAt: number = Date.now();
sendOperationStart(operationId, "vscode.executeDocumentSymbolProvider");
try {
return await commands.executeCommand<SymbolInformation[]>(
"vscode.executeDocumentSymbolProvider",
document.uri,
);
} catch (err) {
error = err;
throw err;
} finally {
const duration = Date.now() - startAt;
sendOperationEnd(operationId, "vscode.executeDocumentSymbolProvider", duration, error);
}
}
protected get command(): Command {
return {
title: "Open source file content",
command: Commands.VSCODE_OPEN,
arguments: [Uri.parse(this.uri || ""), { preserveFocus: true }],
};
}
protected get contextValue(): string {
let contextValue: string = Explorer.ContextValueType.Type;
const type = this.nodeData.metaData?.[PrimaryTypeNode.K_TYPE_KIND];
if (type === TypeKind.Enum) {
contextValue += "+enum";
} else if (type === TypeKind.Interface) {
contextValue += "+interface";
} else {
contextValue += "+class";
}
if (isTest(this._rootNode?.nodeData)) {
contextValue += "+test";
}
return contextValue;
}
}