Turn BootJavaConfig into a Bean

This commit is contained in:
Kris De Volder
2019-03-26 13:52:30 -07:00
parent 28f9f859c2
commit da1f00ec5b
3 changed files with 36 additions and 20 deletions

View File

@@ -8,19 +8,36 @@
* Contributors:
* Pivotal, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.ide.vscode.boot.java;
package org.springframework.ide.vscode.boot.app;
import java.util.function.Consumer;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.ide.vscode.commons.languageserver.util.ListenerList;
import org.springframework.ide.vscode.commons.languageserver.util.Settings;
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer;
import org.springframework.ide.vscode.commons.languageserver.util.SimpleWorkspaceService;
import org.springframework.stereotype.Component;
/**
* Boot-Java LS settings
*
* @author Alex Boyko
*
*/
public class BootJavaConfig {
@Component
public class BootJavaConfig implements InitializingBean {
//TODO: Consider changing this to something that raises Spring application events.
// I.e. like described in here: https://www.baeldung.com/spring-events
private final SimpleWorkspaceService workspace;
private Settings settings = new Settings(null);
private ListenerList<Void> listeners = new ListenerList<Void>();
BootJavaConfig(SimpleLanguageServer server) {
this.workspace = server.getWorkspaceService();
}
public boolean isBootHintsEnabled() {
Boolean enabled = settings.getBoolean("boot-java", "boot-hints", "on");
@@ -39,7 +56,15 @@ public class BootJavaConfig {
public void handleConfigurationChange(Settings newConfig) {
this.settings = newConfig;
listeners.fire(null);
}
public void addListener(Consumer<Void> l) {
listeners.add(l);
}
@Override
public void afterPropertiesSet() throws Exception {
workspace.onDidChangeConfiguraton(this::handleConfigurationChange);
}
}

View File

@@ -48,6 +48,7 @@ public class BootLanguageServerInitializer implements InitializingBean {
@Autowired YamlStructureProvider yamlStructureProvider;
@Autowired YamlAssistContextProvider yamlAssistContextProvider;
@Autowired SymbolCache symbolCache;
@Autowired BootJavaConfig config;
@Qualifier("adHocProperties") @Autowired ProjectBasedPropertyIndexProvider adHocProperties;
@@ -73,7 +74,7 @@ public class BootLanguageServerInitializer implements InitializingBean {
// some server intialization code. Migrate that code and get rid of the ComposableLanguageServer class
CompositeLanguageServerComponents.Builder builder = new CompositeLanguageServerComponents.Builder();
builder.add(new BootPropertiesLanguageServerComponents(server, params, javaElementLocationProvider, parser, yamlStructureProvider, yamlAssistContextProvider, sourceLinks));
builder.add(new BootJavaLanguageServerComponents(server, params, sourceLinks, cuCache, adHocProperties, symbolCache));
builder.add(new BootJavaLanguageServerComponents(server, params, sourceLinks, cuCache, adHocProperties, symbolCache, config));
components = builder.build(server);
params.projectObserver.addListener(reconcileOpenDocuments(server, components));

View File

@@ -20,6 +20,7 @@ import org.eclipse.lsp4j.CompletionItemKind;
import org.eclipse.lsp4j.InitializeParams;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ide.vscode.boot.app.BootJavaConfig;
import org.springframework.ide.vscode.boot.app.BootLanguageServerParams;
import org.springframework.ide.vscode.boot.java.annotations.AnnotationHierarchyAwareLookup;
import org.springframework.ide.vscode.boot.java.autowired.AutowiredHoverProvider;
@@ -58,12 +59,10 @@ import org.springframework.ide.vscode.boot.java.snippets.JavaSnippetContext;
import org.springframework.ide.vscode.boot.java.snippets.JavaSnippetManager;
import org.springframework.ide.vscode.boot.java.utils.CompilationUnitCache;
import org.springframework.ide.vscode.boot.java.utils.RestrictedDefaultSymbolProvider;
import org.springframework.ide.vscode.boot.java.utils.SpringSymbolIndex;
import org.springframework.ide.vscode.boot.java.utils.SymbolCache;
import org.springframework.ide.vscode.boot.java.utils.SymbolCacheOnDisc;
import org.springframework.ide.vscode.boot.java.utils.SymbolCacheVoid;
import org.springframework.ide.vscode.boot.java.utils.SpringLiveChangeDetectionWatchdog;
import org.springframework.ide.vscode.boot.java.utils.SpringLiveHoverWatchdog;
import org.springframework.ide.vscode.boot.java.utils.SpringSymbolIndex;
import org.springframework.ide.vscode.boot.java.utils.SymbolCache;
import org.springframework.ide.vscode.boot.java.value.ValueCompletionProcessor;
import org.springframework.ide.vscode.boot.java.value.ValueHoverProvider;
import org.springframework.ide.vscode.boot.java.value.ValuePropertyReferencesProvider;
@@ -113,7 +112,6 @@ public class BootJavaLanguageServerComponents implements LanguageServerComponent
private final SpringLiveHoverWatchdog liveHoverWatchdog;
private final SpringLiveChangeDetectionWatchdog liveChangeDetectionWatchdog;
private final ProjectObserver projectObserver;
private final BootJavaConfig config;
private final CompilationUnitCache cuCache;
private JavaProjectFinder projectFinder;
@@ -127,13 +125,12 @@ public class BootJavaLanguageServerComponents implements LanguageServerComponent
SourceLinks sourceLinks,
CompilationUnitCache cuCache,
ProjectBasedPropertyIndexProvider adHocIndexProvider,
SymbolCache symbolCache
SymbolCache symbolCache,
BootJavaConfig config
) {
this.server = server;
this.serverParams = serverParams;
this.config = new BootJavaConfig();
projectFinder = serverParams.projectFinder;
projectObserver = serverParams.projectObserver;
this.cuCache = cuCache;
@@ -210,9 +207,7 @@ public class BootJavaLanguageServerComponents implements LanguageServerComponent
highlightsEngine = createDocumentHighlightEngine();
documents.onDocumentHighlight(highlightsEngine);
workspaceService.onDidChangeConfiguraton(settings -> {
config.handleConfigurationChange(settings);
config.addListener(ignore -> {
// live hover watchdog
if (config.isBootHintsEnabled()) {
liveHoverWatchdog.enableHighlights();
@@ -222,7 +217,6 @@ public class BootJavaLanguageServerComponents implements LanguageServerComponent
indexer.configureIndexer(config.isSpringXMLSupportEnabled());
// live change detection watchdog
if (config.isChangeDetectionEnabled()) {
liveChangeDetectionWatchdog.enableHighlights();
@@ -472,10 +466,6 @@ public class BootJavaLanguageServerComponents implements LanguageServerComponent
return propertyIndexProvider;
}
public BootJavaConfig getConfig() {
return config;
}
public CompilationUnitCache getCompilationUnitCache() {
return cuCache;
}