Skip to content

Commit bb51280

Browse files
committed
GH-1431: let bean index elements create document symbols on-demand
1 parent 888669a commit bb51280

23 files changed

+123
-94
lines changed

headless-services/commons/commons-lsp-extensions/src/main/java/org/springframework/ide/vscode/commons/protocol/spring/Bean.java

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2023, 2024 VMware, Inc.
2+
* Copyright (c) 2023, 2025 VMware, Inc.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -12,11 +12,13 @@
1212

1313
import java.util.Set;
1414

15+
import org.eclipse.lsp4j.DocumentSymbol;
1516
import org.eclipse.lsp4j.Location;
17+
import org.eclipse.lsp4j.SymbolKind;
1618

1719
import com.google.gson.Gson;
1820

19-
public class Bean extends AbstractSpringIndexElement {
21+
public class Bean extends AbstractSpringIndexElement implements SymbolElement {
2022

2123
private final String name;
2224
private final String type;
@@ -25,6 +27,7 @@ public class Bean extends AbstractSpringIndexElement {
2527
private final Set<String> supertypes;
2628
private final AnnotationMetadata[] annotations;
2729
private final boolean isConfiguration;
30+
private final String symbolLabel;
2831

2932
public Bean(
3033
String name,
@@ -33,12 +36,14 @@ public Bean(
3336
InjectionPoint[] injectionPoints,
3437
Set<String> supertypes,
3538
AnnotationMetadata[] annotations,
36-
boolean isConfiguration) {
39+
boolean isConfiguration,
40+
String symbolLabel) {
3741

3842
this.name = name;
3943
this.type = type;
4044
this.location = location;
4145
this.isConfiguration = isConfiguration;
46+
this.symbolLabel = symbolLabel;
4247

4348
if (injectionPoints != null && injectionPoints.length == 0) {
4449
this.injectionPoints = DefaultValues.EMPTY_INJECTION_POINTS;
@@ -93,14 +98,30 @@ public boolean isConfiguration() {
9398
return isConfiguration;
9499
}
95100

101+
public Set<String> getSupertypes() {
102+
return supertypes;
103+
}
104+
105+
public String getSymbolLabel() {
106+
return symbolLabel;
107+
}
108+
109+
@Override
110+
public DocumentSymbol getDocumentSymbol() {
111+
DocumentSymbol symbol = new DocumentSymbol();
112+
113+
symbol.setName(this.symbolLabel);
114+
symbol.setKind(SymbolKind.Interface);
115+
symbol.setRange(this.location.getRange());
116+
symbol.setSelectionRange(this.location.getRange());
117+
118+
return symbol;
119+
}
120+
96121
@Override
97122
public String toString() {
98123
Gson gson = new Gson();
99124
return gson.toJson(this);
100125
}
101126

102-
public Set<String> getSupertypes() {
103-
return supertypes;
104-
}
105-
106127
}

headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/index/cache/IndexCacheOnDisc.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,10 @@ public Bean deserialize(JsonElement json, Type type, JsonDeserializationContext
449449

450450
JsonElement isConfigurationObject = parsedObject.get("isConfiguration");
451451
boolean isConfiguration = context.deserialize(isConfigurationObject, boolean.class);
452+
453+
String symbolLabel = parsedObject.get("symbolLabel").getAsString();
452454

453-
return new Bean(beanName, beanType, location, injectionPoints, supertypes, annotations, isConfiguration);
455+
return new Bean(beanName, beanType, location, injectionPoints, supertypes, annotations, isConfiguration, symbolLabel);
454456
}
455457
}
456458

headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/index/cache/IndexCacheOnDiscDeltaBased.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,11 +659,14 @@ public Bean deserialize(JsonElement json, Type type, JsonDeserializationContext
659659
JsonElement isConfigurationObject = parsedObject.get("isConfiguration");
660660
boolean isConfiguration = context.deserialize(isConfigurationObject, boolean.class);
661661

662+
String symbolLabel = parsedObject.get("symbolLabel").getAsString();
663+
662664
JsonElement childrenObject = parsedObject.get("children");
663665
Type childrenListType = TypeToken.getParameterized(List.class, SpringIndexElement.class).getType();
664666
List<SpringIndexElement> children = context.deserialize(childrenObject, childrenListType);
665667

666-
Bean bean = new Bean(beanName, beanType, location, injectionPoints, supertypes, annotations, isConfiguration);
668+
Bean bean = new Bean(beanName, beanType, location, injectionPoints, supertypes, annotations, isConfiguration, symbolLabel);
669+
667670
for (SpringIndexElement springIndexElement : children) {
668671
bean.addChild(springIndexElement);
669672
}
@@ -685,6 +688,7 @@ public JsonElement serialize(Bean src, Type typeOfSrc, JsonSerializationContext
685688
bean.add("annotations", context.serialize(src.getAnnotations()));
686689

687690
bean.addProperty("isConfiguration", src.isConfiguration());
691+
bean.addProperty("symbolLabel", src.getSymbolLabel());
688692

689693
Type childrenListType = TypeToken.getParameterized(List.class, SpringIndexElement.class).getType();
690694
bean.add("children", context.serialize(src.getChildren(), childrenListType));

headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/beans/BeansSymbolProvider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public void addSymbols(Annotation node, ITypeBinding typeBinding, Collection<ITy
113113
Collection<Annotation> annotationsOnMethod = ASTUtils.getAnnotations(method);
114114
AnnotationMetadata[] annotations = ASTUtils.getAnnotationsMetadata(annotationsOnMethod, doc);
115115

116-
Bean beanDefinition = new Bean(nameAndRegion.getT1(), beanType.getQualifiedName(), location, injectionPoints, supertypes, annotations, false);
116+
Bean beanDefinition = new Bean(nameAndRegion.getT1(), beanType.getQualifiedName(), location, injectionPoints, supertypes, annotations, false, symbol.getName());
117117
if (childElements.size() > 0) {
118118
for (SpringIndexElement springIndexElement : childElements) {
119119
beanDefinition.addChild(springIndexElement);
@@ -174,7 +174,7 @@ protected void addSymbolsPass1(TypeDeclaration typeDeclaration, SpringIndexerJav
174174

175175
InjectionPoint[] injectionPoints = ASTUtils.findInjectionPoints(typeDeclaration, doc);
176176

177-
Bean beanDefinition = new Bean(beanName, concreteBeanType.getQualifiedName(), beanLocation, injectionPoints, supertypes, annotations, false);
177+
Bean beanDefinition = new Bean(beanName, concreteBeanType.getQualifiedName(), beanLocation, injectionPoints, supertypes, annotations, false, symbol.getName());
178178
context.getBeans().add(new CachedBean(context.getDocURI(), beanDefinition));
179179

180180
} catch (BadLocationException e) {

headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/beans/ComponentSymbolProvider.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import org.springframework.ide.vscode.commons.protocol.spring.AnnotationMetadata;
4545
import org.springframework.ide.vscode.commons.protocol.spring.Bean;
4646
import org.springframework.ide.vscode.commons.protocol.spring.InjectionPoint;
47+
import org.springframework.ide.vscode.commons.protocol.spring.SimpleSymbolElement;
4748
import org.springframework.ide.vscode.commons.util.BadLocationException;
4849
import org.springframework.ide.vscode.commons.util.text.DocumentRegion;
4950
import org.springframework.ide.vscode.commons.util.text.TextDocument;
@@ -65,6 +66,7 @@ protected void addSymbolsPass1(Annotation node, ITypeBinding annotationType, Col
6566
else if (Annotations.NAMED_ANNOTATIONS.contains(annotationType.getQualifiedName())) {
6667
WorkspaceSymbol symbol = DefaultSymbolProvider.provideDefaultSymbol(node, doc);
6768
context.getGeneratedSymbols().add(new CachedSymbol(context.getDocURI(), context.getLastModified(), symbol));
69+
context.getBeans().add(new CachedBean(context.getDocURI(), new SimpleSymbolElement(symbol)));
6870
}
6971
}
7072
catch (Exception e) {
@@ -107,7 +109,7 @@ protected void createSymbol(Annotation node, ITypeBinding annotationType, Collec
107109
.map(an -> new AnnotationMetadata(an.getQualifiedName(), true, null, null)))
108110
.toArray(AnnotationMetadata[]::new);
109111

110-
Bean beanDefinition = new Bean(beanName, beanType.getQualifiedName(), location, injectionPoints, supertypes, annotations, isConfiguration);
112+
Bean beanDefinition = new Bean(beanName, beanType.getQualifiedName(), location, injectionPoints, supertypes, annotations, isConfiguration, symbol.getName());
111113

112114
// type implements event listener - move those already created event index elements under the bean node
113115
List<CachedBean> alreadyCreatedEventListenerChilds = context.getBeans().stream()

headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/beans/FeignClientSymbolProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ private Two<WorkspaceSymbol, Bean> createSymbol(Annotation node, ITypeBinding an
9494
.map(an -> new AnnotationMetadata(an.getQualifiedName(), true, null, null)))
9595
.toArray(AnnotationMetadata[]::new);
9696

97-
Bean beanDefinition = new Bean(beanName, beanType == null ? "" : beanType.getQualifiedName(), location, injectionPoints, supertypes, annotations, false);
97+
Bean beanDefinition = new Bean(beanName, beanType == null ? "" : beanType.getQualifiedName(), location, injectionPoints, supertypes, annotations, false, symbol.getName());
9898

9999
return Tuple.two(symbol, beanDefinition);
100100
}

headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/data/DataRepositorySymbolProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ protected void addSymbolsPass1(TypeDeclaration typeDeclaration, SpringIndexerJav
7474
Collection<Annotation> annotationsOnMethod = ASTUtils.getAnnotations(typeDeclaration);
7575
AnnotationMetadata[] annotations = ASTUtils.getAnnotationsMetadata(annotationsOnMethod, doc);
7676

77-
Bean beanDefinition = new Bean(beanName, concreteRepoType, location, injectionPoints, supertypes, annotations, false);
77+
Bean beanDefinition = new Bean(beanName, concreteRepoType, location, injectionPoints, supertypes, annotations, false, symbol.getName());
7878

7979
context.getGeneratedSymbols().add(new CachedSymbol(context.getDocURI(), context.getLastModified(), symbol));
8080
context.getBeans().add(new CachedBean(context.getDocURI(), beanDefinition));

headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/utils/SpringIndexerXMLNamespaceHandlerBeans.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ else if (name != null && name.equals("class")) {
9595
generatedSymbols.add(cachedSymbol);
9696

9797
// TODO: bean index
98-
generatedBeans.add(new CachedBean(docURI, new Bean(beanID, fqBeanClass, location, null, null, null, false)));
98+
generatedBeans.add(new CachedBean(docURI, new Bean(beanID, fqBeanClass, location, null, null, null, false, symbol.getName())));
9999
}
100100
}
101101

0 commit comments

Comments
 (0)