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