Skip to content

Commit

Permalink
Settings for bean injection completion and bean structure
Browse files Browse the repository at this point in the history
  • Loading branch information
BoykoAlex committed Feb 28, 2025
1 parent 9ccbc32 commit d4bbdf4
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017, 2024 Pivotal, Inc.
* Copyright (c) 2017, 2025 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -52,4 +52,8 @@ public class Constants {

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

public static final String PREF_COMPLETION_JAVA_INJECT_BEAN = "boot-java.java.completions.inject-bean";

public static final String PREF_BEANS_STRUCTURE_TREE = "boot-java.java.beans-structure-tree";

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017, 2024 Pivotal, Inc.
* Copyright (c) 2017, 2025 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -182,8 +182,8 @@ private void sendConfiguration() {
Map<String, Object> supportXML = new HashMap<>();
Map<String, Object> bootChangeDetection = new HashMap<>();
Map<String, Object> scanTestJavaSources = new HashMap<>();
Map<String, Object> validation = new HashMap<>();
Map<String, Object> javaValidation = new HashMap<>();
Map<String, Object> javaSettings = new HashMap<>();
Map<String, Object> javaCompletionSettings = new HashMap<>();

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

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

javaValidation.put("reconcilers", preferenceStore.getBoolean(Constants.PREF_JAVA_RECONCILE));
validation.put("java", javaValidation);
javaCompletionSettings.put("inject-bean", preferenceStore.getBoolean(Constants.PREF_COMPLETION_JAVA_INJECT_BEAN));

javaSettings.put("beans-structure-tree", preferenceStore.getBoolean(Constants.PREF_BEANS_STRUCTURE_TREE));
javaSettings.put("completions", javaCompletionSettings);
javaSettings.put("reconcilers", preferenceStore.getBoolean(Constants.PREF_JAVA_RECONCILE));

bootJavaObj.put("jpql", preferenceStore.getBoolean(Constants.PREF_JPQL));
bootJavaObj.put("live-information", liveInformation);
bootJavaObj.put("support-spring-xml-config", supportXML);
bootJavaObj.put("change-detection", bootChangeDetection);
bootJavaObj.put("scan-java-test-sources", scanTestJavaSources);
bootJavaObj.put("change-detection", bootChangeDetection);
bootJavaObj.put("validation", validation);
bootJavaObj.put("java", javaSettings);
bootJavaObj.put("remote-apps", getAllRemoteApps());
bootJavaObj.put("modulith-project-tracking", preferenceStore.getBoolean(Constants.PREF_MODULITH));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017, 2024 Pivotal, Inc.
* Copyright (c) 2017, 2025 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -54,6 +54,12 @@ protected void createFieldEditors() {

// Experimental Modulith support
addField(new BooleanFieldEditor(Constants.PREF_MODULITH, "Spring Boot Modulith automatic project tracking and metadata update", fieldEditorParent));

// Experimental Bean Injections completion in Java editor
addField(new BooleanFieldEditor(Constants.PREF_COMPLETION_JAVA_INJECT_BEAN, "Inject Bean completion proposals in Java editor", fieldEditorParent));

// Experimental Beans tree
addField(new BooleanFieldEditor(Constants.PREF_BEANS_STRUCTURE_TREE, "Beans structure tree in the outline view", fieldEditorParent));

Composite c = new Composite(fieldEditorParent, SWT.NONE);
GridDataFactory.fillDefaults().grab(true, false).applyTo(c);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017, 2024 Pivotal, Inc.
* Copyright (c) 2017, 2025 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -69,6 +69,10 @@ public void initializeDefaultPreferences() {
preferenceStore.setDefault(Constants.PREF_PROPS_COMPLETIONS_ELIDE_PREFIX, false);

preferenceStore.setDefault(Constants.PREF_CRON_INLAY_HINTS, true);

preferenceStore.setDefault(Constants.PREF_COMPLETION_JAVA_INJECT_BEAN, true);

preferenceStore.setDefault(Constants.PREF_BEANS_STRUCTURE_TREE, false);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2020, 2024 Pivotal, Inc.
* Copyright (c) 2020, 2025 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -116,7 +116,8 @@ BootJavaCompletionEngine javaCompletionEngine(
JavaSnippetManager snippetManager,
CompilationUnitCache cuCache,
SpringMetamodelIndex springIndex,
RewriteRefactorings rewriteRefactorings ) {
RewriteRefactorings rewriteRefactorings,
BootJavaConfig config) {

SpringPropertyIndexProvider indexProvider = params.indexProvider;
JavaProjectFinder javaProjectFinder = params.projectFinder;
Expand Down Expand Up @@ -171,7 +172,7 @@ BootJavaCompletionEngine javaCompletionEngine(
providers.put(Annotations.SCHEDULED, new AnnotationAttributeCompletionProcessor(javaProjectFinder, Map.of(
"cron", new CronExpressionCompletionProvider())));

providers.put(Annotations.BEAN, new BeanCompletionProvider(javaProjectFinder, springIndex, rewriteRefactorings));
providers.put(Annotations.BEAN, new BeanCompletionProvider(javaProjectFinder, springIndex, rewriteRefactorings, config));

return new BootJavaCompletionEngine(cuCache, providers, snippetManager);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017, 2024 Pivotal, Inc.
* Copyright (c) 2017, 2025 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -168,7 +168,7 @@ public boolean areXmlHyperlinksEnabled() {
}

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

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

public boolean isBeanInjectionCompletionEnabled() {
Boolean b = settings.getBoolean("boot-java", "java", "completions", "inject-bean");
return Boolean.TRUE.equals(b);
}

public boolean isBeanStructureTreeEnabled() {
Boolean b = settings.getBoolean("boot-java", "java", "beans-structure-tree");
return Boolean.TRUE.equals(b);
}

public Settings getRawSettings() {
return settings;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,8 @@ public List<? extends WorkspaceSymbol> getSymbols(String docURI) {
}

public List<? extends DocumentSymbol> getDocumentSymbols(String docURI) {
if (System.getProperty(OUTLINE_SYMBOLS_FROM_INDEX_PROPERTY) != null) {
if (System.getProperty(OUTLINE_SYMBOLS_FROM_INDEX_PROPERTY) != null
|| config.isBeanStructureTreeEnabled()) {
return getDocumentSymbolsFromMetamodelIndex(docURI);
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.eclipse.jdt.core.dom.VariableDeclaration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ide.vscode.boot.app.BootJavaConfig;
import org.springframework.ide.vscode.boot.index.SpringMetamodelIndex;
import org.springframework.ide.vscode.boot.java.Annotations;
import org.springframework.ide.vscode.boot.java.annotations.AnnotationHierarchies;
Expand All @@ -51,17 +52,21 @@ public class BeanCompletionProvider implements CompletionProvider {
private final SpringMetamodelIndex springIndex;
private final RewriteRefactorings rewriteRefactorings;

private final BootJavaConfig config;

public BeanCompletionProvider(JavaProjectFinder javaProjectFinder, SpringMetamodelIndex springIndex,
RewriteRefactorings rewriteRefactorings) {
RewriteRefactorings rewriteRefactorings, BootJavaConfig config) {
this.javaProjectFinder = javaProjectFinder;
this.springIndex = springIndex;
this.rewriteRefactorings = rewriteRefactorings;
this.config = config;
}

@Override
public void provideCompletions(ASTNode node, int offset, TextDocument doc,
Collection<ICompletionProposal> completions) {
if (node instanceof SimpleName || node instanceof Block || node instanceof FieldAccess) {
if (config.isBeanInjectionCompletionEnabled()
&& (node instanceof SimpleName || node instanceof Block || node instanceof FieldAccess)) {
try {

if (node instanceof SimpleName) {
Expand Down
12 changes: 11 additions & 1 deletion vscode-extensions/vscode-spring-boot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@
"default": true,
"description": "Syntax Hyghlighting for Languages embedded into Java source code"
},
"boot-java.validation.java.reconcilers": {
"boot-java.java.reconcilers": {
"type": "boolean",
"default": true,
"description": "Reconciling Java Sources"
Expand Down Expand Up @@ -363,6 +363,16 @@
"default": false,
"description": "Enable/Disable detecting changes of running Spring Boot applications"
},
"boot-java.java.completions.inject-bean": {
"type": "boolean",
"default": true,
"description": "Inject Bean completion proposals in Java editor"
},
"boot-java.java.beans-structure-tree": {
"type": "boolean",
"default": false,
"description": "Beans structure tree in the outline view"
},
"boot-java.remote-apps": {
"type": "array",
"items": {
Expand Down

0 comments on commit d4bbdf4

Please sign in to comment.