1414import java .util .List ;
1515
1616import org .eclipse .lsp4j .DocumentSymbol ;
17- import org .eclipse .lsp4j .Position ;
18- import org .eclipse .lsp4j .Range ;
19- import org .eclipse .lsp4j .SymbolKind ;
2017import org .springframework .ide .vscode .commons .protocol .spring .SpringIndexElement ;
2118import org .springframework .ide .vscode .commons .protocol .spring .SymbolElement ;
2219
@@ -26,41 +23,40 @@ public static List<DocumentSymbol> createDocumentSymbols(List<SpringIndexElement
2623 List <DocumentSymbol > result = new ArrayList <>();
2724
2825 for (SpringIndexElement indexElement : indexElements ) {
29- result .add (createSymbol (indexElement ));
26+ result .addAll (createSymbol (indexElement ));
3027 }
3128
3229 return result ;
3330 }
3431
35- private static DocumentSymbol createSymbol (SpringIndexElement indexElement ) {
36-
37- DocumentSymbol symbol = null ;
38- if (indexElement instanceof SymbolElement symbolElement ) {
39- symbol = symbolElement .getDocumentSymbol ();
40- }
41- else {
42- symbol = new DocumentSymbol (indexElement .toString (), SymbolKind .String ,
43- new Range (new Position (), new Position ()),
44- new Range (new Position (), new Position ()));
45- }
32+ private static List <DocumentSymbol > createSymbol (SpringIndexElement indexElement ) {
4633
34+ List <DocumentSymbol > subTreeSymbols = new ArrayList <>();
4735 List <SpringIndexElement > children = indexElement .getChildren ();
36+
4837 if (children != null && children .size () > 0 ) {
49- List <DocumentSymbol > childSymbols = new ArrayList <>();
50-
5138 for (SpringIndexElement child : children ) {
52- DocumentSymbol childSymbol = createSymbol (child );
53- if (childSymbol != null ) {
54- childSymbols . add ( childSymbol );
39+ List < DocumentSymbol > childSymbols = createSymbol (child );
40+ if (childSymbols != null ) {
41+ subTreeSymbols . addAll ( childSymbols );
5542 }
5643 }
57-
58- if (childSymbols .size () > 0 ) {
59- symbol .setChildren (childSymbols );
60- }
6144 }
6245
63- return symbol ;
46+ if (indexElement instanceof SymbolElement symbolElement ) {
47+ DocumentSymbol documentSymbol = symbolElement .getDocumentSymbol ();
48+ if (subTreeSymbols .size () > 0 ) {
49+ documentSymbol .setChildren (subTreeSymbols );
50+ }
51+
52+ return List .of (documentSymbol );
53+ }
54+ else {
55+ // symbol = new DocumentSymbol(indexElement.toString(), SymbolKind.String,
56+ // new Range(new Position(), new Position()),
57+ // new Range(new Position(), new Position()));
58+ return subTreeSymbols ;
59+ }
6460 }
6561
6662}
0 commit comments