Skip to content

Commit d4bbdf4

Browse files
committed
Settings for bean injection completion and bean structure
1 parent 9ccbc32 commit d4bbdf4

File tree

9 files changed

+62
-18
lines changed

9 files changed

+62
-18
lines changed

eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/Constants.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2017, 2024 Pivotal, Inc.
2+
* Copyright (c) 2017, 2025 Pivotal, 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
@@ -52,4 +52,8 @@ public class Constants {
5252

5353
public static final String PREF_CRON_INLAY_HINTS = "boot-java.cron.inlay-hints";
5454

55+
public static final String PREF_COMPLETION_JAVA_INJECT_BEAN = "boot-java.java.completions.inject-bean";
56+
57+
public static final String PREF_BEANS_STRUCTURE_TREE = "boot-java.java.beans-structure-tree";
58+
5559
}

eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/DelegatingStreamConnectionProvider.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2017, 2024 Pivotal, Inc.
2+
* Copyright (c) 2017, 2025 Pivotal, 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
@@ -182,8 +182,8 @@ private void sendConfiguration() {
182182
Map<String, Object> supportXML = new HashMap<>();
183183
Map<String, Object> bootChangeDetection = new HashMap<>();
184184
Map<String, Object> scanTestJavaSources = new HashMap<>();
185-
Map<String, Object> validation = new HashMap<>();
186-
Map<String, Object> javaValidation = new HashMap<>();
185+
Map<String, Object> javaSettings = new HashMap<>();
186+
Map<String, Object> javaCompletionSettings = new HashMap<>();
187187

188188
IPreferenceStore preferenceStore = BootLanguageServerPlugin.getDefault().getPreferenceStore();
189189

@@ -200,16 +200,19 @@ private void sendConfiguration() {
200200
bootChangeDetection.put("on", preferenceStore.getBoolean(Constants.PREF_CHANGE_DETECTION));
201201
scanTestJavaSources.put("on", preferenceStore.getBoolean(Constants.PREF_SCAN_JAVA_TEST_SOURCES));
202202

203-
javaValidation.put("reconcilers", preferenceStore.getBoolean(Constants.PREF_JAVA_RECONCILE));
204-
validation.put("java", javaValidation);
203+
javaCompletionSettings.put("inject-bean", preferenceStore.getBoolean(Constants.PREF_COMPLETION_JAVA_INJECT_BEAN));
204+
205+
javaSettings.put("beans-structure-tree", preferenceStore.getBoolean(Constants.PREF_BEANS_STRUCTURE_TREE));
206+
javaSettings.put("completions", javaCompletionSettings);
207+
javaSettings.put("reconcilers", preferenceStore.getBoolean(Constants.PREF_JAVA_RECONCILE));
205208

206209
bootJavaObj.put("jpql", preferenceStore.getBoolean(Constants.PREF_JPQL));
207210
bootJavaObj.put("live-information", liveInformation);
208211
bootJavaObj.put("support-spring-xml-config", supportXML);
209212
bootJavaObj.put("change-detection", bootChangeDetection);
210213
bootJavaObj.put("scan-java-test-sources", scanTestJavaSources);
211214
bootJavaObj.put("change-detection", bootChangeDetection);
212-
bootJavaObj.put("validation", validation);
215+
bootJavaObj.put("java", javaSettings);
213216
bootJavaObj.put("remote-apps", getAllRemoteApps());
214217
bootJavaObj.put("modulith-project-tracking", preferenceStore.getBoolean(Constants.PREF_MODULITH));
215218

eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/prefs/BootJavaPreferencesPage.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2017, 2024 Pivotal, Inc.
2+
* Copyright (c) 2017, 2025 Pivotal, 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
@@ -54,6 +54,12 @@ protected void createFieldEditors() {
5454

5555
// Experimental Modulith support
5656
addField(new BooleanFieldEditor(Constants.PREF_MODULITH, "Spring Boot Modulith automatic project tracking and metadata update", fieldEditorParent));
57+
58+
// Experimental Bean Injections completion in Java editor
59+
addField(new BooleanFieldEditor(Constants.PREF_COMPLETION_JAVA_INJECT_BEAN, "Inject Bean completion proposals in Java editor", fieldEditorParent));
60+
61+
// Experimental Beans tree
62+
addField(new BooleanFieldEditor(Constants.PREF_BEANS_STRUCTURE_TREE, "Beans structure tree in the outline view", fieldEditorParent));
5763

5864
Composite c = new Composite(fieldEditorParent, SWT.NONE);
5965
GridDataFactory.fillDefaults().grab(true, false).applyTo(c);

eclipse-language-servers/org.springframework.tooling.boot.ls/src/org/springframework/tooling/boot/ls/prefs/PrefsInitializer.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2017, 2024 Pivotal, Inc.
2+
* Copyright (c) 2017, 2025 Pivotal, 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
@@ -69,6 +69,10 @@ public void initializeDefaultPreferences() {
6969
preferenceStore.setDefault(Constants.PREF_PROPS_COMPLETIONS_ELIDE_PREFIX, false);
7070

7171
preferenceStore.setDefault(Constants.PREF_CRON_INLAY_HINTS, true);
72+
73+
preferenceStore.setDefault(Constants.PREF_COMPLETION_JAVA_INJECT_BEAN, true);
74+
75+
preferenceStore.setDefault(Constants.PREF_BEANS_STRUCTURE_TREE, false);
7276
}
7377

7478
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2020, 2024 Pivotal, Inc.
2+
* Copyright (c) 2020, 2025 Pivotal, 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
@@ -116,7 +116,8 @@ BootJavaCompletionEngine javaCompletionEngine(
116116
JavaSnippetManager snippetManager,
117117
CompilationUnitCache cuCache,
118118
SpringMetamodelIndex springIndex,
119-
RewriteRefactorings rewriteRefactorings ) {
119+
RewriteRefactorings rewriteRefactorings,
120+
BootJavaConfig config) {
120121

121122
SpringPropertyIndexProvider indexProvider = params.indexProvider;
122123
JavaProjectFinder javaProjectFinder = params.projectFinder;
@@ -171,7 +172,7 @@ BootJavaCompletionEngine javaCompletionEngine(
171172
providers.put(Annotations.SCHEDULED, new AnnotationAttributeCompletionProcessor(javaProjectFinder, Map.of(
172173
"cron", new CronExpressionCompletionProvider())));
173174

174-
providers.put(Annotations.BEAN, new BeanCompletionProvider(javaProjectFinder, springIndex, rewriteRefactorings));
175+
providers.put(Annotations.BEAN, new BeanCompletionProvider(javaProjectFinder, springIndex, rewriteRefactorings, config));
175176

176177
return new BootJavaCompletionEngine(cuCache, providers, snippetManager);
177178
}

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2017, 2024 Pivotal, Inc.
2+
* Copyright (c) 2017, 2025 Pivotal, 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
@@ -168,7 +168,7 @@ public boolean areXmlHyperlinksEnabled() {
168168
}
169169

170170
public boolean isJavaSourceReconcileEnabled() {
171-
Boolean enabled = getRawSettings().getBoolean("boot-java", "validation", "java", "reconcilers");
171+
Boolean enabled = getRawSettings().getBoolean("boot-java", "java", "reconcilers");
172172
return enabled == null ? true : enabled.booleanValue();
173173
}
174174

@@ -214,6 +214,16 @@ public Path getCommonPropertiesFile() {
214214
return str == null || str.isBlank() ? null : Paths.get(str);
215215
}
216216

217+
public boolean isBeanInjectionCompletionEnabled() {
218+
Boolean b = settings.getBoolean("boot-java", "java", "completions", "inject-bean");
219+
return Boolean.TRUE.equals(b);
220+
}
221+
222+
public boolean isBeanStructureTreeEnabled() {
223+
Boolean b = settings.getBoolean("boot-java", "java", "beans-structure-tree");
224+
return Boolean.TRUE.equals(b);
225+
}
226+
217227
public Settings getRawSettings() {
218228
return settings;
219229
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,8 @@ public List<? extends WorkspaceSymbol> getSymbols(String docURI) {
708708
}
709709

710710
public List<? extends DocumentSymbol> getDocumentSymbols(String docURI) {
711-
if (System.getProperty(OUTLINE_SYMBOLS_FROM_INDEX_PROPERTY) != null) {
711+
if (System.getProperty(OUTLINE_SYMBOLS_FROM_INDEX_PROPERTY) != null
712+
|| config.isBeanStructureTreeEnabled()) {
712713
return getDocumentSymbolsFromMetamodelIndex(docURI);
713714
}
714715
else {

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.eclipse.jdt.core.dom.VariableDeclaration;
3030
import org.slf4j.Logger;
3131
import org.slf4j.LoggerFactory;
32+
import org.springframework.ide.vscode.boot.app.BootJavaConfig;
3233
import org.springframework.ide.vscode.boot.index.SpringMetamodelIndex;
3334
import org.springframework.ide.vscode.boot.java.Annotations;
3435
import org.springframework.ide.vscode.boot.java.annotations.AnnotationHierarchies;
@@ -51,17 +52,21 @@ public class BeanCompletionProvider implements CompletionProvider {
5152
private final SpringMetamodelIndex springIndex;
5253
private final RewriteRefactorings rewriteRefactorings;
5354

55+
private final BootJavaConfig config;
56+
5457
public BeanCompletionProvider(JavaProjectFinder javaProjectFinder, SpringMetamodelIndex springIndex,
55-
RewriteRefactorings rewriteRefactorings) {
58+
RewriteRefactorings rewriteRefactorings, BootJavaConfig config) {
5659
this.javaProjectFinder = javaProjectFinder;
5760
this.springIndex = springIndex;
5861
this.rewriteRefactorings = rewriteRefactorings;
62+
this.config = config;
5963
}
6064

6165
@Override
6266
public void provideCompletions(ASTNode node, int offset, TextDocument doc,
6367
Collection<ICompletionProposal> completions) {
64-
if (node instanceof SimpleName || node instanceof Block || node instanceof FieldAccess) {
68+
if (config.isBeanInjectionCompletionEnabled()
69+
&& (node instanceof SimpleName || node instanceof Block || node instanceof FieldAccess)) {
6570
try {
6671

6772
if (node instanceof SimpleName) {

vscode-extensions/vscode-spring-boot/package.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@
281281
"default": true,
282282
"description": "Syntax Hyghlighting for Languages embedded into Java source code"
283283
},
284-
"boot-java.validation.java.reconcilers": {
284+
"boot-java.java.reconcilers": {
285285
"type": "boolean",
286286
"default": true,
287287
"description": "Reconciling Java Sources"
@@ -363,6 +363,16 @@
363363
"default": false,
364364
"description": "Enable/Disable detecting changes of running Spring Boot applications"
365365
},
366+
"boot-java.java.completions.inject-bean": {
367+
"type": "boolean",
368+
"default": true,
369+
"description": "Inject Bean completion proposals in Java editor"
370+
},
371+
"boot-java.java.beans-structure-tree": {
372+
"type": "boolean",
373+
"default": false,
374+
"description": "Beans structure tree in the outline view"
375+
},
366376
"boot-java.remote-apps": {
367377
"type": "array",
368378
"items": {

0 commit comments

Comments
 (0)