Clear property index when json metadata is changed
This commit is contained in:
@@ -116,7 +116,9 @@ public class DelegatingStreamConnectionProvider implements StreamConnectionProvi
|
||||
FileSystems.getDefault().getPathMatcher("glob:**/pom.xml"),
|
||||
FileSystems.getDefault().getPathMatcher("glob:**/*.gradle"),
|
||||
FileSystems.getDefault().getPathMatcher("glob:**/*.java"),
|
||||
FileSystems.getDefault().getPathMatcher("glob:**/*.class")
|
||||
FileSystems.getDefault().getPathMatcher("glob:**/*.json"),
|
||||
FileSystems.getDefault().getPathMatcher("glob:**/*.yml"),
|
||||
FileSystems.getDefault().getPathMatcher("glob:**/*.properties")
|
||||
)));
|
||||
|
||||
//Add remote boot apps listener
|
||||
|
||||
@@ -44,6 +44,7 @@ import org.springframework.ide.vscode.commons.maven.MavenCore;
|
||||
import org.springframework.ide.vscode.commons.maven.java.MavenProjectCache;
|
||||
import org.springframework.ide.vscode.commons.maven.java.MavenProjectFinder;
|
||||
import org.springframework.ide.vscode.commons.util.Assert;
|
||||
import org.springframework.ide.vscode.commons.util.FileObserver;
|
||||
import org.springframework.ide.vscode.commons.util.text.IDocument;
|
||||
|
||||
/**
|
||||
@@ -91,7 +92,9 @@ public class BootLanguageServerParams {
|
||||
new JdtLsProjectCache(server),
|
||||
() -> createFallbackProjectCache(server)
|
||||
);
|
||||
DefaultSpringPropertyIndexProvider indexProvider = new DefaultSpringPropertyIndexProvider(jdtProjectCache, jdtProjectCache, valueProviders);
|
||||
|
||||
FileObserver fileObserver = server.getWorkspaceService().getFileObserver();
|
||||
DefaultSpringPropertyIndexProvider indexProvider = new DefaultSpringPropertyIndexProvider(jdtProjectCache, jdtProjectCache, fileObserver, valueProviders);
|
||||
indexProvider.setProgressService(server.getProgressService());
|
||||
|
||||
return new BootLanguageServerParams(
|
||||
@@ -154,7 +157,7 @@ public class BootLanguageServerParams {
|
||||
|
||||
CompositeProjectOvserver projectObserver = new CompositeProjectOvserver(Arrays.asList(mavenProjectCache, gradleProjectCache));
|
||||
|
||||
DefaultSpringPropertyIndexProvider indexProvider = new DefaultSpringPropertyIndexProvider(javaProjectFinder, projectObserver, valueProviders);
|
||||
DefaultSpringPropertyIndexProvider indexProvider = new DefaultSpringPropertyIndexProvider(javaProjectFinder, projectObserver, null, valueProviders);
|
||||
indexProvider.setProgressService(server.getProgressService());
|
||||
|
||||
return new BootLanguageServerParams(
|
||||
|
||||
@@ -18,6 +18,7 @@ import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.languageserver.ProgressService;
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder;
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.ProjectObserver;
|
||||
import org.springframework.ide.vscode.commons.util.FileObserver;
|
||||
import org.springframework.ide.vscode.commons.util.FuzzyMap;
|
||||
import org.springframework.ide.vscode.commons.util.text.IDocument;
|
||||
|
||||
@@ -28,9 +29,9 @@ public class DefaultSpringPropertyIndexProvider implements SpringPropertyIndexPr
|
||||
|
||||
private ProgressService progressService = (id, msg) -> { /*ignore*/ };
|
||||
|
||||
public DefaultSpringPropertyIndexProvider(JavaProjectFinder javaProjectFinder, ProjectObserver projectObserver, ValueProviderRegistry valueProviders) {
|
||||
public DefaultSpringPropertyIndexProvider(JavaProjectFinder javaProjectFinder, ProjectObserver projectObserver, FileObserver fileObserver, ValueProviderRegistry valueProviders) {
|
||||
this.javaProjectFinder = javaProjectFinder;
|
||||
this.indexManager = new SpringPropertiesIndexManager(valueProviders, projectObserver);
|
||||
this.indexManager = new SpringPropertiesIndexManager(valueProviders, projectObserver, fileObserver);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -29,7 +29,7 @@ import org.springframework.ide.vscode.commons.util.Log;
|
||||
|
||||
public class PropertiesLoader {
|
||||
|
||||
private static final String MAIN_SPRING_CONFIGURATION_METADATA_JSON = "META-INF/spring-configuration-metadata.json";
|
||||
public static final String MAIN_SPRING_CONFIGURATION_METADATA_JSON = "META-INF/spring-configuration-metadata.json";
|
||||
|
||||
public static final String ADDITIONAL_SPRING_CONFIGURATION_METADATA_JSON = "META-INF/additional-spring-configuration-metadata.json";
|
||||
|
||||
|
||||
@@ -17,10 +17,12 @@ import org.springframework.ide.vscode.boot.metadata.util.ListenerManager;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.languageserver.ProgressService;
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.ProjectObserver;
|
||||
import org.springframework.ide.vscode.commons.util.FileObserver;
|
||||
import org.springframework.ide.vscode.commons.util.Log;
|
||||
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
/**
|
||||
* Support for Reconciling, Content Assist and Hover Text in spring properties
|
||||
@@ -36,13 +38,18 @@ public class SpringPropertiesIndexManager extends ListenerManager<Listener<Sprin
|
||||
private final ValueProviderRegistry valueProviders;
|
||||
private static int progressIdCt = 0;
|
||||
|
||||
public SpringPropertiesIndexManager(ValueProviderRegistry valueProviders, ProjectObserver projectObserver) {
|
||||
public SpringPropertiesIndexManager(ValueProviderRegistry valueProviders, ProjectObserver projectObserver, FileObserver fileObserver) {
|
||||
this.valueProviders = valueProviders;
|
||||
this.indexes = CacheBuilder.newBuilder()
|
||||
.build();
|
||||
if (projectObserver != null) {
|
||||
projectObserver.addListener(ProjectObserver.onAny(project -> indexes.invalidate(project)));
|
||||
}
|
||||
if (fileObserver!=null) {
|
||||
fileObserver.onAnyChange(ImmutableList.of("**/*spring-configuration-metadata.json"), changed -> {
|
||||
clear();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized SpringPropertyIndex get(IJavaProject project, ProgressService progressService) {
|
||||
|
||||
@@ -63,8 +63,6 @@ public abstract class AbstractPropsEditorTest {
|
||||
}
|
||||
}));
|
||||
|
||||
|
||||
|
||||
abstract public Editor newEditor(String contents) throws Exception;
|
||||
|
||||
private IJavaProject getTestProject() {
|
||||
|
||||
@@ -36,7 +36,7 @@ public class PropertiesIndexTest {
|
||||
@Test
|
||||
public void springStandardPropertyPresent_Maven() throws Exception {
|
||||
SpringPropertiesIndexManager indexManager = new SpringPropertiesIndexManager(
|
||||
new ValueProviderRegistry(), null);
|
||||
new ValueProviderRegistry(), null, null);
|
||||
IJavaProject mavenProject = projects.mavenProject(CUSTOM_PROPERTIES_PROJECT);
|
||||
FuzzyMap<PropertyInfo> index = indexManager.get(mavenProject, progressService);
|
||||
PropertyInfo propertyInfo = index.get("server.port");
|
||||
@@ -48,7 +48,7 @@ public class PropertiesIndexTest {
|
||||
@Test
|
||||
public void customPropertyPresent_Maven() throws Exception {
|
||||
SpringPropertiesIndexManager indexManager = new SpringPropertiesIndexManager(
|
||||
new ValueProviderRegistry(), null);
|
||||
new ValueProviderRegistry(), null, null);
|
||||
IJavaProject mavenProject = projects.mavenProject(CUSTOM_PROPERTIES_PROJECT);
|
||||
FuzzyMap<PropertyInfo> index = indexManager.get(mavenProject, progressService);
|
||||
PropertyInfo propertyInfo = index.get("demo.settings.user");
|
||||
@@ -60,7 +60,7 @@ public class PropertiesIndexTest {
|
||||
@Test
|
||||
public void propertyNotPresent_Maven() throws Exception {
|
||||
SpringPropertiesIndexManager indexManager = new SpringPropertiesIndexManager(
|
||||
new ValueProviderRegistry(), null);
|
||||
new ValueProviderRegistry(), null, null);
|
||||
IJavaProject mavenProject = projects.mavenProject(CUSTOM_PROPERTIES_PROJECT);
|
||||
FuzzyMap<PropertyInfo> index = indexManager.get(mavenProject, progressService);
|
||||
PropertyInfo propertyInfo = index.get("my.server.port");
|
||||
|
||||
Reference in New Issue
Block a user