reducing index-in-progress messages to real index situations
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2016-2017 Pivotal, Inc.
|
||||
* Copyright (c) 2016, 2017 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
|
||||
@@ -23,7 +23,6 @@ public class DefaultSpringPropertyIndexProvider implements SpringPropertyIndexPr
|
||||
private SpringPropertiesIndexManager indexManager = new SpringPropertiesIndexManager(ValueProviderRegistry.getDefault());
|
||||
|
||||
private ProgressService progressService = (id, msg) -> { /*ignore*/ };
|
||||
private static int progressIdCt = 0;
|
||||
|
||||
public DefaultSpringPropertyIndexProvider(JavaProjectFinder javaProjectFinder) {
|
||||
this.javaProjectFinder = javaProjectFinder;
|
||||
@@ -31,23 +30,13 @@ public class DefaultSpringPropertyIndexProvider implements SpringPropertyIndexPr
|
||||
|
||||
@Override
|
||||
public FuzzyMap<PropertyInfo> getIndex(IDocument doc) {
|
||||
String progressId = getProgressId();
|
||||
progressService.progressEvent(progressId, "Indexing Spring Boot Properties...");
|
||||
try {
|
||||
IJavaProject jp = javaProjectFinder.find(doc);
|
||||
if (jp!=null) {
|
||||
return indexManager.get(jp);
|
||||
}
|
||||
} finally {
|
||||
progressService.progressEvent(progressId, null);
|
||||
IJavaProject jp = javaProjectFinder.find(doc);
|
||||
if (jp!=null) {
|
||||
return indexManager.get(jp, progressService);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static synchronized String getProgressId() {
|
||||
return DefaultSpringPropertyIndexProvider.class.getName()+ (progressIdCt++);
|
||||
}
|
||||
|
||||
public void setProgressService(ProgressService progressService) {
|
||||
this.progressService = progressService;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2014 Pivotal, Inc.
|
||||
* Copyright (c) 2014, 2017 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
|
||||
@@ -17,6 +17,7 @@ import org.springframework.ide.vscode.boot.metadata.util.FuzzyMap;
|
||||
import org.springframework.ide.vscode.boot.metadata.util.Listener;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Support for Reconciling, Content Assist and Hover Text in spring properties
|
||||
@@ -29,20 +30,30 @@ import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
public class SpringPropertiesIndexManager extends ListenerManager<Listener<SpringPropertiesIndexManager>> {
|
||||
|
||||
private Map<IJavaProject, SpringPropertyIndex> indexes = null;
|
||||
final private ValueProviderRegistry valueProviders;
|
||||
private final ValueProviderRegistry valueProviders;
|
||||
private static int progressIdCt = 0;
|
||||
|
||||
public SpringPropertiesIndexManager(ValueProviderRegistry valueProviders) {
|
||||
this.valueProviders = valueProviders;
|
||||
}
|
||||
|
||||
public synchronized FuzzyMap<PropertyInfo> get(IJavaProject project) {
|
||||
public synchronized FuzzyMap<PropertyInfo> get(IJavaProject project, ProgressService progressService) {
|
||||
if (indexes==null) {
|
||||
indexes = new HashMap<>();
|
||||
}
|
||||
SpringPropertyIndex index = indexes.get(project);
|
||||
if (index==null) {
|
||||
String progressId = getProgressId();
|
||||
if (progressService != null) {
|
||||
progressService.progressEvent(progressId, "Indexing Spring Boot Properties...");
|
||||
}
|
||||
|
||||
index = new SpringPropertyIndex(valueProviders, project.getClasspath());
|
||||
indexes.put(project, index);
|
||||
|
||||
if (progressService != null) {
|
||||
progressService.progressEvent(progressId, null);
|
||||
}
|
||||
}
|
||||
return index;
|
||||
}
|
||||
@@ -56,4 +67,8 @@ public class SpringPropertiesIndexManager extends ListenerManager<Listener<Sprin
|
||||
}
|
||||
}
|
||||
|
||||
private static synchronized String getProgressId() {
|
||||
return DefaultSpringPropertyIndexProvider.class.getName()+ (progressIdCt++);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2016 Pivotal, Inc.
|
||||
* Copyright (c) 2016, 2017 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
|
||||
@@ -20,6 +20,7 @@ import org.springframework.ide.vscode.boot.metadata.SpringPropertiesIndexManager
|
||||
import org.springframework.ide.vscode.boot.metadata.ValueProviderRegistry;
|
||||
import org.springframework.ide.vscode.boot.metadata.util.FuzzyMap;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.languageserver.ProgressService;
|
||||
import org.springframework.ide.vscode.project.harness.ProjectsHarness;
|
||||
|
||||
/**
|
||||
@@ -33,13 +34,14 @@ public class PropertiesIndexTest {
|
||||
private static final String CUSTOM_PROPERTIES_PROJECT = "custom-properties-boot-project";
|
||||
|
||||
private ProjectsHarness projects = ProjectsHarness.INSTANCE;
|
||||
private ProgressService progressService = (id, msg) -> { /*ignore*/ };
|
||||
|
||||
@Test
|
||||
public void springStandardPropertyPresent_Maven() throws Exception {
|
||||
SpringPropertiesIndexManager indexManager = new SpringPropertiesIndexManager(
|
||||
ValueProviderRegistry.getDefault());
|
||||
IJavaProject mavenProject = projects.mavenProject(CUSTOM_PROPERTIES_PROJECT);
|
||||
FuzzyMap<PropertyInfo> index = indexManager.get(mavenProject);
|
||||
FuzzyMap<PropertyInfo> index = indexManager.get(mavenProject, progressService);
|
||||
PropertyInfo propertyInfo = index.get("server.port");
|
||||
assertNotNull(propertyInfo);
|
||||
assertEquals(Integer.class.getName(), propertyInfo.getType());
|
||||
@@ -51,7 +53,7 @@ public class PropertiesIndexTest {
|
||||
SpringPropertiesIndexManager indexManager = new SpringPropertiesIndexManager(
|
||||
ValueProviderRegistry.getDefault());
|
||||
IJavaProject mavenProject = projects.mavenProject(CUSTOM_PROPERTIES_PROJECT);
|
||||
FuzzyMap<PropertyInfo> index = indexManager.get(mavenProject);
|
||||
FuzzyMap<PropertyInfo> index = indexManager.get(mavenProject, progressService);
|
||||
PropertyInfo propertyInfo = index.get("demo.settings.user");
|
||||
assertNotNull(propertyInfo);
|
||||
assertEquals(String.class.getName(), propertyInfo.getType());
|
||||
@@ -63,7 +65,7 @@ public class PropertiesIndexTest {
|
||||
SpringPropertiesIndexManager indexManager = new SpringPropertiesIndexManager(
|
||||
ValueProviderRegistry.getDefault());
|
||||
IJavaProject mavenProject = projects.mavenProject(CUSTOM_PROPERTIES_PROJECT);
|
||||
FuzzyMap<PropertyInfo> index = indexManager.get(mavenProject);
|
||||
FuzzyMap<PropertyInfo> index = indexManager.get(mavenProject, progressService);
|
||||
PropertyInfo propertyInfo = index.get("my.server.port");
|
||||
assertNull(propertyInfo);
|
||||
}
|
||||
@@ -73,7 +75,7 @@ public class PropertiesIndexTest {
|
||||
SpringPropertiesIndexManager indexManager = new SpringPropertiesIndexManager(
|
||||
ValueProviderRegistry.getDefault());
|
||||
IJavaProject classpathFileProject = projects.javaProjectWithClasspathFile(CUSTOM_PROPERTIES_PROJECT);
|
||||
FuzzyMap<PropertyInfo> index = indexManager.get(classpathFileProject);
|
||||
FuzzyMap<PropertyInfo> index = indexManager.get(classpathFileProject, progressService);
|
||||
PropertyInfo propertyInfo = index.get("server.port");
|
||||
assertNotNull(propertyInfo);
|
||||
assertEquals(Integer.class.getName(), propertyInfo.getType());
|
||||
@@ -85,7 +87,7 @@ public class PropertiesIndexTest {
|
||||
SpringPropertiesIndexManager indexManager = new SpringPropertiesIndexManager(
|
||||
ValueProviderRegistry.getDefault());
|
||||
IJavaProject classpathFileProject = projects.javaProjectWithClasspathFile(CUSTOM_PROPERTIES_PROJECT);
|
||||
FuzzyMap<PropertyInfo> index = indexManager.get(classpathFileProject);
|
||||
FuzzyMap<PropertyInfo> index = indexManager.get(classpathFileProject, progressService);
|
||||
PropertyInfo propertyInfo = index.get("demo.settings.user");
|
||||
assertNotNull(propertyInfo);
|
||||
assertEquals(String.class.getName(), propertyInfo.getType());
|
||||
@@ -97,7 +99,7 @@ public class PropertiesIndexTest {
|
||||
SpringPropertiesIndexManager indexManager = new SpringPropertiesIndexManager(
|
||||
ValueProviderRegistry.getDefault());
|
||||
IJavaProject classpathFileProject = projects.javaProjectWithClasspathFile(CUSTOM_PROPERTIES_PROJECT);
|
||||
FuzzyMap<PropertyInfo> index = indexManager.get(classpathFileProject);
|
||||
FuzzyMap<PropertyInfo> index = indexManager.get(classpathFileProject, progressService);
|
||||
PropertyInfo propertyInfo = index.get("my.server.port");
|
||||
assertNull(propertyInfo);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user