Make SymbolCache into a bean

The main application bean is defined 2ith @ConditionalOn
in such a way that it is not enabled during testing.
That way, tests can supply their own implementation.
This commit is contained in:
Kris De Volder
2019-03-25 13:23:55 -07:00
parent 47935c96bf
commit 3d08365fce
9 changed files with 68 additions and 29 deletions

View File

@@ -27,6 +27,9 @@ import org.springframework.ide.vscode.boot.java.links.JdtJavaDocumentUriProvider
import org.springframework.ide.vscode.boot.java.links.SourceLinkFactory;
import org.springframework.ide.vscode.boot.java.links.SourceLinks;
import org.springframework.ide.vscode.boot.java.utils.CompilationUnitCache;
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.metadata.AdHocSpringPropertyIndexProvider;
import org.springframework.ide.vscode.boot.metadata.ClassReferenceProvider;
import org.springframework.ide.vscode.boot.metadata.LoggerNameProvider;
@@ -63,6 +66,19 @@ public class BootLanguagServerBootApp {
return SERVER_NAME;
}
@ConditionalOnMissingClass("org.springframework.ide.vscode.languageserver.testharness.LanguageServerHarness")
@Bean
SymbolCache symbolCache() {
//TODO: Don't use system properties. This should be done via 'proper' spring boot property. That way it can
// be controlled via sysprop or via application.yml, or via env var etc.
//Question... who sets this property? I don't find anything setting this.
if ("true".equals(System.getProperty("boot.ls.symbols.caching.enabled", "true"))) {
return new SymbolCacheOnDisc();
} else {
return new SymbolCacheVoid();
}
}
@ConditionalOnMissingClass("org.springframework.ide.vscode.languageserver.testharness.LanguageServerHarness")
@Bean AdHocSpringPropertyIndexProvider adHocProperties(BootLanguageServerParams params, FileObserver fileObserver, DocumentEventListenerManager documentEvents) {
return new AdHocSpringPropertyIndexProvider(params.projectFinder, params.projectObserver, fileObserver, documentEvents);

View File

@@ -19,6 +19,7 @@ import org.springframework.ide.vscode.boot.java.BootJavaLanguageServerComponents
import org.springframework.ide.vscode.boot.java.links.JavaElementLocationProvider;
import org.springframework.ide.vscode.boot.java.links.SourceLinks;
import org.springframework.ide.vscode.boot.java.utils.CompilationUnitCache;
import org.springframework.ide.vscode.boot.java.utils.SymbolCache;
import org.springframework.ide.vscode.boot.metadata.ProjectBasedPropertyIndexProvider;
import org.springframework.ide.vscode.boot.properties.BootPropertiesLanguageServerComponents;
import org.springframework.ide.vscode.commons.languageserver.completion.ICompletionEngine;
@@ -46,6 +47,7 @@ public class BootLanguageServerInitializer implements InitializingBean {
@Autowired YamlASTProvider parser;
@Autowired YamlStructureProvider yamlStructureProvider;
@Autowired YamlAssistContextProvider yamlAssistContextProvider;
@Autowired SymbolCache symbolCache;
@Qualifier("adHocProperties") @Autowired ProjectBasedPropertyIndexProvider adHocProperties;
@@ -71,7 +73,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));
builder.add(new BootJavaLanguageServerComponents(server, params, sourceLinks, cuCache, adHocProperties, symbolCache));
components = builder.build(server);
params.projectObserver.addListener(reconcileOpenDocuments(server, components));

View File

@@ -60,6 +60,13 @@ import org.springframework.ide.vscode.commons.util.text.IDocument;
*/
public class BootLanguageServerParams {
//TODO: This class is supposed to go away. It is basically a 'collection of beans'.
// I.e. all the 'components' in here should really become separate beans.
// So... moving forward...
// Do not add more components here. You should instead just make your new
// components into separate beans.
//Shared
public final JavaProjectFinder projectFinder;
public final ProjectObserver projectObserver;
@@ -71,7 +78,6 @@ public class BootLanguageServerParams {
//Boot Java
public final RunningAppProvider runningAppProvider;
public final Duration watchDogInterval;
public final SymbolCache symbolCache;
public BootLanguageServerParams(
JavaProjectFinder projectFinder,
@@ -79,8 +85,8 @@ public class BootLanguageServerParams {
SpringPropertyIndexProvider indexProvider,
TypeUtilProvider typeUtilProvider,
RunningAppProvider runningAppProvider,
Duration watchDogInterval,
SymbolCache symbolCache) {
Duration watchDogInterval
) {
super();
Assert.isNotNull(projectObserver); // null is bad should be ProjectObserver.NULL
this.projectFinder = projectFinder;
@@ -89,7 +95,6 @@ public class BootLanguageServerParams {
this.typeUtilProvider = typeUtilProvider;
this.runningAppProvider = runningAppProvider;
this.watchDogInterval = watchDogInterval;
this.symbolCache = symbolCache;
}
public static BootLanguageServerParams createDefault(SimpleLanguageServer server, ValueProviderRegistry valueProviders, boolean isJandexIndex) {
@@ -104,22 +109,13 @@ public class BootLanguageServerParams {
DefaultSpringPropertyIndexProvider indexProvider = new DefaultSpringPropertyIndexProvider(jdtProjectCache, jdtProjectCache, fileObserver, valueProviders);
indexProvider.setProgressService(server.getProgressService());
SymbolCache symbolCache = null;
if ("true".equals(System.getProperty("boot.ls.symbols.caching.enabled", "true"))) {
symbolCache = new SymbolCacheOnDisc();
}
else {
symbolCache = new SymbolCacheVoid();
}
return new BootLanguageServerParams(
jdtProjectCache.filter(project -> SpringProjectUtil.isBootProject(project) || SpringProjectUtil.isSpringProject(project)),
jdtProjectCache,
indexProvider,
(SourceLinks sourceLinks, IDocument doc) -> new TypeUtil(sourceLinks, jdtProjectCache.find(new TextDocumentIdentifier(doc.getUri()))),
RunningAppProvider.createDefault(server),
SpringLiveHoverWatchdog.DEFAULT_INTERVAL,
symbolCache
SpringLiveHoverWatchdog.DEFAULT_INTERVAL
);
}
@@ -187,8 +183,7 @@ public class BootLanguageServerParams {
indexProvider,
(SourceLinks sourceLinks, IDocument doc) -> new TypeUtil(sourceLinks, javaProjectFinder.find(new TextDocumentIdentifier(doc.getUri()))),
RunningAppProvider.NULL,
SpringLiveHoverWatchdog.DEFAULT_INTERVAL,
new SymbolCacheVoid()
SpringLiveHoverWatchdog.DEFAULT_INTERVAL
);
}
}

View File

@@ -94,6 +94,13 @@ import com.google.common.collect.ImmutableSet;
*/
public class BootJavaLanguageServerComponents implements LanguageServerComponents {
//TODO: This class is supposed to go away. It is basically a 'collection of beans'.
// I.e. all the 'components' in here should really become separate beans.
// So... moving forward...
// Do not add more components here. You should instead just make your new
// components into separate beans.
private static final Set<LanguageId> LANGUAGES = ImmutableSet.of(LanguageId.JAVA, LanguageId.XML);
private static final Logger log = LoggerFactory.getLogger(BootJavaLanguageServerComponents.class);
@@ -114,14 +121,13 @@ public class BootJavaLanguageServerComponents implements LanguageServerComponent
private CodeLensHandler codeLensHandler;
private DocumentHighlightHandler highlightsEngine;
private SymbolCache symbolCache;
public BootJavaLanguageServerComponents(
SimpleLanguageServer server,
BootLanguageServerParams serverParams,
SourceLinks sourceLinks,
CompilationUnitCache cuCache,
ProjectBasedPropertyIndexProvider adHocIndexProvider
ProjectBasedPropertyIndexProvider adHocIndexProvider,
SymbolCache symbolCache
) {
this.server = server;
this.serverParams = serverParams;
@@ -141,7 +147,6 @@ public class BootJavaLanguageServerComponents implements LanguageServerComponent
ReferencesHandler referencesHandler = createReferenceHandler(server, projectFinder);
documents.onReferences(referencesHandler);
this.symbolCache = this.serverParams.symbolCache;
this.indexer = createAnnotationIndexer(server, serverParams, symbolCache);
documents.onDidSave(params -> {

View File

@@ -19,6 +19,7 @@ import org.springframework.ide.vscode.boot.app.BootLanguageServerParams;
import org.springframework.ide.vscode.boot.editor.harness.PropertyIndexHarness;
import org.springframework.ide.vscode.boot.java.links.SourceLinkFactory;
import org.springframework.ide.vscode.boot.java.links.SourceLinks;
import org.springframework.ide.vscode.boot.java.utils.SymbolCache;
import org.springframework.ide.vscode.boot.java.utils.SymbolCacheVoid;
import org.springframework.ide.vscode.boot.metadata.ValueProviderRegistry;
import org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder;
@@ -31,6 +32,10 @@ import org.springframework.ide.vscode.project.harness.MockRunningAppProvider;
@Import(AdHocPropertyHarnessTestConf.class)
public class HoverTestConf {
@Bean SymbolCache symbolCache() {
return new SymbolCacheVoid();
}
@Bean PropertyIndexHarness indexHarness(ValueProviderRegistry valueProviders) {
return new PropertyIndexHarness(valueProviders);
}
@@ -55,8 +60,7 @@ public class HoverTestConf {
indexHarness.getIndexProvider(),
testDefaults.typeUtilProvider,
mockAppsHarness().provider,
watchDogInterval(),
new SymbolCacheVoid()
watchDogInterval()
);
}

View File

@@ -22,6 +22,7 @@ import org.springframework.ide.vscode.boot.java.links.SourceLinkFactory;
import org.springframework.ide.vscode.boot.java.links.SourceLinks;
import org.springframework.ide.vscode.boot.java.utils.CompilationUnitCache;
import org.springframework.ide.vscode.boot.java.utils.SpringLiveHoverWatchdog;
import org.springframework.ide.vscode.boot.java.utils.SymbolCache;
import org.springframework.ide.vscode.boot.java.utils.SymbolCacheVoid;
import org.springframework.ide.vscode.boot.metadata.ValueProviderRegistry;
import org.springframework.ide.vscode.boot.metadata.types.TypeUtil;
@@ -39,6 +40,10 @@ import org.springframework.ide.vscode.project.harness.MockRunningAppProvider;
@Import(AdHocPropertyHarnessTestConf.class)
public class PropertyEditorTestConf {
@Bean SymbolCache symbolCache() {
return new SymbolCacheVoid();
}
@Bean PropertyIndexHarness indexHarness(ValueProviderRegistry valueProviders) {
return new PropertyIndexHarness(valueProviders);
}
@@ -68,8 +73,7 @@ public class PropertyEditorTestConf {
indexHarness.getIndexProvider(),
typeUtilProvider,
mockAppsHarness().provider,
SpringLiveHoverWatchdog.DEFAULT_INTERVAL,
new SymbolCacheVoid()
SpringLiveHoverWatchdog.DEFAULT_INTERVAL
);
}

View File

@@ -20,6 +20,7 @@ import org.springframework.ide.vscode.boot.java.BootJavaLanguageServerComponents
import org.springframework.ide.vscode.boot.java.links.SourceLinkFactory;
import org.springframework.ide.vscode.boot.java.links.SourceLinks;
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.SymbolCacheVoid;
import org.springframework.ide.vscode.boot.metadata.DefaultSpringPropertyIndexProvider;
import org.springframework.ide.vscode.boot.metadata.ValueProviderRegistry;
@@ -32,6 +33,10 @@ import org.springframework.ide.vscode.project.harness.BootLanguageServerHarness;
@Import(AdHocPropertyHarnessTestConf.class)
public class SymbolProviderTestConf {
@Bean public SymbolCache symbolCache() {
return new SymbolCacheVoid();
}
@Bean PropertyIndexHarness indexHarness(ValueProviderRegistry valueProviders) {
return new PropertyIndexHarness(valueProviders);
}

View File

@@ -38,6 +38,7 @@ import org.springframework.ide.vscode.boot.java.handlers.RunningAppProvider;
import org.springframework.ide.vscode.boot.java.links.SourceLinkFactory;
import org.springframework.ide.vscode.boot.java.links.SourceLinks;
import org.springframework.ide.vscode.boot.java.utils.CompilationUnitCache;
import org.springframework.ide.vscode.boot.java.utils.SymbolCache;
import org.springframework.ide.vscode.boot.java.utils.SymbolCacheVoid;
import org.springframework.ide.vscode.boot.metadata.ValueProviderRegistry;
import org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder;
@@ -74,6 +75,10 @@ public class CompilationUnitCacheTest {
@Import(AdHocPropertyHarnessTestConf.class)
@Configuration static class TestConf {
@Bean SymbolCache symbolCache() {
return new SymbolCacheVoid();
}
@Bean PropertyIndexHarness indexHarness(ValueProviderRegistry valueProviders) {
return new PropertyIndexHarness(valueProviders);
}
@@ -98,8 +103,7 @@ public class CompilationUnitCacheTest {
indexHarness.getIndexProvider(),
testDefaults.typeUtilProvider,
RunningAppProvider.NULL,
null,
new SymbolCacheVoid()
null
);
}

View File

@@ -40,6 +40,7 @@ import org.springframework.ide.vscode.boot.java.handlers.RunningAppProvider;
import org.springframework.ide.vscode.boot.java.links.SourceLinkFactory;
import org.springframework.ide.vscode.boot.java.links.SourceLinks;
import org.springframework.ide.vscode.boot.java.utils.CompilationUnitCache;
import org.springframework.ide.vscode.boot.java.utils.SymbolCache;
import org.springframework.ide.vscode.boot.java.utils.SymbolCacheVoid;
import org.springframework.ide.vscode.boot.java.value.ValueCompletionProcessor;
import org.springframework.ide.vscode.boot.metadata.AdHocSpringPropertyIndexProvider;
@@ -118,11 +119,14 @@ public class ValueCompletionTest {
indexHarness.getIndexProvider(),
testDefaults.typeUtilProvider,
RunningAppProvider.NULL,
null,
new SymbolCacheVoid()
null
);
}
@Bean SymbolCache symbolCache() {
return new SymbolCacheVoid();
}
@Bean SourceLinks sourceLinks(SimpleTextDocumentService documents, CompilationUnitCache cuCache) {
return SourceLinkFactory.NO_SOURCE_LINKS;
}