@@ -12,6 +12,28 @@ export default async function documentSymbolProvider(handler: DocumentSymbolPara
12
12
return def . range . start !== null && def . range . start >= 0 && def . range . end !== null ;
13
13
}
14
14
15
+ const expandStruct = ( def : Declaration ) : DocumentSymbol => {
16
+ let start = def . range . start || def . position . range . line ;
17
+ let end = def . range . end || def . position . range . line ;
18
+ let hasChildren = def . subItems && def . subItems . length > 0 ;
19
+
20
+ const parent = DocumentSymbol . create (
21
+ def . name ,
22
+ prettyKeywords ( def . keyword ) ,
23
+ hasChildren ? SymbolKind . Struct : SymbolKind . Property ,
24
+ Range . create ( start , 0 , end , 0 ) ,
25
+ Range . create ( start , 0 , start , 0 ) ,
26
+ ) ;
27
+
28
+ if ( hasChildren ) {
29
+ parent . children = def . subItems
30
+ . filter ( subitem => subitem . position && subitem . position . path === currentPath )
31
+ . map ( subitem => expandStruct ( subitem ) ) ;
32
+ }
33
+
34
+ return parent ;
35
+ }
36
+
15
37
if ( document ) {
16
38
const doc = await parser . getDocs ( currentPath , document . getText ( ) ) ;
17
39
@@ -143,25 +165,7 @@ export default async function documentSymbolProvider(handler: DocumentSymbolPara
143
165
scope . structs
144
166
. filter ( struct => struct . position && struct . position . path === currentPath && validRange ( struct ) )
145
167
. forEach ( struct => {
146
- const structDef = DocumentSymbol . create (
147
- struct . name ,
148
- prettyKeywords ( struct . keyword ) ,
149
- SymbolKind . Struct ,
150
- Range . create ( struct . range . start ! , 0 , struct . range . end ! , 0 ) ,
151
- Range . create ( struct . range . start ! , 0 , struct . range . start ! , 0 ) ,
152
- ) ;
153
-
154
- structDef . children = struct . subItems
155
- . filter ( subitem => subitem . position && subitem . position . path === currentPath )
156
- . map ( subitem => DocumentSymbol . create (
157
- subitem . name ,
158
- prettyKeywords ( subitem . keyword ) ,
159
- SymbolKind . Property ,
160
- Range . create ( subitem . position . range . line , 0 , subitem . position . range . line , 0 ) ,
161
- Range . create ( subitem . position . range . line , 0 , subitem . position . range . line , 0 )
162
- ) ) ;
163
-
164
- currentScopeDefs . push ( structDef ) ;
168
+ currentScopeDefs . push ( expandStruct ( struct ) ) ;
165
169
} ) ;
166
170
167
171
return currentScopeDefs ;
0 commit comments