GH-1083: integrate fingerprint of validation settings into diagnostics cache
This commit is contained in:
@@ -958,7 +958,7 @@ public class LanguageServerHarness {
|
||||
}
|
||||
|
||||
public void changeConfiguration(Settings settings) {
|
||||
getServer().getWorkspaceService().didChangeConfiguration(new DidChangeConfigurationParams(settings));
|
||||
getServer().getWorkspaceService().didChangeConfiguration(new DidChangeConfigurationParams(settings.getRawSettings()));
|
||||
}
|
||||
|
||||
public SimpleLanguageServer getServer() {
|
||||
|
||||
@@ -250,7 +250,7 @@ public class SpringSymbolIndex implements InitializingBean, SpringIndex {
|
||||
reconcilers.add(new BeanMethodNotPublicReconciler(server.getQuickfixRegistry()));
|
||||
|
||||
BiFunction<AtomicReference<TextDocument>, BiConsumer<String, Diagnostic>, IProblemCollector> problemCollectorFactory = (docRef, aggregator) -> server.createProblemCollector(docRef, aggregator);
|
||||
springIndexerJava = new SpringIndexerJava(handler, specificProviders, this.cache, projectFinder(), server.getProgressService(), reconcilers, problemCollectorFactory);
|
||||
springIndexerJava = new SpringIndexerJava(handler, specificProviders, this.cache, projectFinder(), server.getProgressService(), reconcilers, problemCollectorFactory, config.getJavaValidationSettingsJson());
|
||||
|
||||
factoriesIndexer = new SpringFactoriesIndexer(handler, cache);
|
||||
|
||||
@@ -278,14 +278,12 @@ public class SpringSymbolIndex implements InitializingBean, SpringIndex {
|
||||
|
||||
config.addListener(evt -> {
|
||||
log.info("update settings of spring indexer - start");
|
||||
|
||||
CompletableFuture.runAsync(() ->
|
||||
configureIndexer(SymbolIndexConfig.builder()
|
||||
.scanXml(config.isSpringXMLSupportEnabled())
|
||||
.xmlScanFolders(config.xmlBeansFoldersToScan())
|
||||
.scanTestJavaSources(config.isScanJavaTestSourcesEnabled())
|
||||
.build()
|
||||
), this.updateQueue);
|
||||
|
||||
configurationChanged(SymbolIndexConfig.builder()
|
||||
.scanXml(config.isSpringXMLSupportEnabled())
|
||||
.xmlScanFolders(config.xmlBeansFoldersToScan())
|
||||
.scanTestJavaSources(config.isScanJavaTestSourcesEnabled())
|
||||
.build());
|
||||
|
||||
log.info("update settings of spring indexer - done");
|
||||
});
|
||||
@@ -309,6 +307,15 @@ public class SpringSymbolIndex implements InitializingBean, SpringIndex {
|
||||
});
|
||||
}
|
||||
|
||||
public void configurationChanged(SymbolIndexConfig config) {
|
||||
CompletableFuture.runAsync(() -> configureIndexer(config), this.updateQueue);
|
||||
|
||||
Collection<? extends IJavaProject> projects = projectFinder().all();
|
||||
for (IJavaProject project : projects) {
|
||||
initializeProject(project, true);
|
||||
}
|
||||
}
|
||||
|
||||
public void configureIndexer(SymbolIndexConfig config) {
|
||||
synchronized (this) {
|
||||
if (config.isScanXml() && !(Arrays.asList(this.indexers).contains(springIndexerXML))) {
|
||||
@@ -326,11 +333,7 @@ public class SpringSymbolIndex implements InitializingBean, SpringIndex {
|
||||
}
|
||||
}
|
||||
springIndexerJava.setScanTestJavaSources(config.isScanTestJavaSources());
|
||||
}
|
||||
|
||||
Collection<? extends IJavaProject> projects = projectFinder().all();
|
||||
for (IJavaProject project : projects) {
|
||||
initializeProject(project, true);
|
||||
springIndexerJava.setValidationSeveritySettings(this.config.getJavaValidationSettingsJson());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -75,6 +75,7 @@ import org.springframework.ide.vscode.commons.util.text.TextDocument;
|
||||
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.MultimapBuilder;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
/**
|
||||
* @author Martin Lippert
|
||||
@@ -104,14 +105,18 @@ public class SpringIndexerJava implements SpringIndexer {
|
||||
private final ProgressService progressService;
|
||||
|
||||
private boolean scanTestJavaSources = false;
|
||||
private JsonObject validationSeveritySettings;
|
||||
|
||||
private FileScanListener fileScanListener = null; //used by test code only
|
||||
|
||||
private final SpringIndexerJavaDependencyTracker dependencyTracker = new SpringIndexerJavaDependencyTracker();
|
||||
private final BiFunction<AtomicReference<TextDocument>, BiConsumer<String, Diagnostic>, IProblemCollector> problemCollectorCreator;
|
||||
|
||||
|
||||
public SpringIndexerJava(SymbolHandler symbolHandler, AnnotationHierarchyAwareLookup<SymbolProvider> symbolProviders, IndexCache cache,
|
||||
JavaProjectFinder projectFimder, ProgressService progressService, List<AnnotationReconciler> reconcilers,
|
||||
BiFunction<AtomicReference<TextDocument>, BiConsumer<String, Diagnostic>, IProblemCollector> problemCollectorCreator) {
|
||||
BiFunction<AtomicReference<TextDocument>, BiConsumer<String, Diagnostic>, IProblemCollector> problemCollectorCreator,
|
||||
JsonObject validationSeveritySettings) {
|
||||
this.symbolHandler = symbolHandler;
|
||||
this.symbolProviders = symbolProviders;
|
||||
this.reconcilers = reconcilers;
|
||||
@@ -120,6 +125,7 @@ public class SpringIndexerJava implements SpringIndexer {
|
||||
this.progressService = progressService;
|
||||
|
||||
this.problemCollectorCreator = problemCollectorCreator;
|
||||
this.validationSeveritySettings = validationSeveritySettings;
|
||||
}
|
||||
|
||||
public SpringIndexerJavaDependencyTracker getDependencyTracker() {
|
||||
@@ -776,7 +782,8 @@ public class SpringIndexerJava implements SpringIndexer {
|
||||
.map(file -> file.getAbsolutePath() + "#" + file.lastModified())
|
||||
.collect(Collectors.joining(","));
|
||||
|
||||
return new IndexCacheKey(project.getElementName(), "java", elementType, DigestUtils.md5Hex(GENERATION + "-" + classpathIdentifier).toUpperCase());
|
||||
// return new IndexCacheKey(project.getElementName(), "java", elementType, DigestUtils.md5Hex(GENERATION + "-" + classpathIdentifier).toUpperCase());
|
||||
return new IndexCacheKey(project.getElementName(), "java", elementType, DigestUtils.md5Hex(GENERATION + "-" + validationSeveritySettings.toString() + "-" + classpathIdentifier).toUpperCase());
|
||||
}
|
||||
|
||||
public void setScanTestJavaSources(boolean scanTestJavaSources) {
|
||||
@@ -840,6 +847,10 @@ public class SpringIndexerJava implements SpringIndexer {
|
||||
}
|
||||
}
|
||||
|
||||
public void setValidationSeveritySettings(JsonObject javaValidationSettingsJson) {
|
||||
this.validationSeveritySettings = javaValidationSettingsJson;
|
||||
}
|
||||
|
||||
public void setFileScanListener(FileScanListener fileScanListener) {
|
||||
this.fileScanListener = fileScanListener;
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ package org.springframework.ide.vscode.boot.java.reconcilers.test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
@@ -20,6 +19,7 @@ import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.eclipse.lsp4j.Diagnostic;
|
||||
import org.eclipse.lsp4j.DiagnosticSeverity;
|
||||
import org.eclipse.lsp4j.PublishDiagnosticsParams;
|
||||
import org.eclipse.lsp4j.TextDocumentIdentifier;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -27,16 +27,21 @@ import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.ide.vscode.boot.app.BootJavaConfig;
|
||||
import org.springframework.ide.vscode.boot.app.BootLanguageServerInitializer;
|
||||
import org.springframework.ide.vscode.boot.app.SpringSymbolIndex;
|
||||
import org.springframework.ide.vscode.boot.bootiful.BootLanguageServerTest;
|
||||
import org.springframework.ide.vscode.boot.bootiful.SymbolProviderTestConf;
|
||||
import org.springframework.ide.vscode.boot.java.Boot2JavaProblemType;
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.Settings;
|
||||
import org.springframework.ide.vscode.project.harness.BootLanguageServerHarness;
|
||||
import org.springframework.ide.vscode.project.harness.ProjectsHarness;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonElement;
|
||||
|
||||
/**
|
||||
* @author Martin Lippert
|
||||
*/
|
||||
@@ -46,6 +51,7 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
public class SpringValidationBeanMethodNotPublicTest {
|
||||
|
||||
@Autowired private BootLanguageServerHarness harness;
|
||||
@Autowired private BootJavaConfig config;
|
||||
@Autowired private BootLanguageServerInitializer serverInit;
|
||||
@Autowired private JavaProjectFinder projectFinder;
|
||||
|
||||
@@ -87,6 +93,36 @@ public class SpringValidationBeanMethodNotPublicTest {
|
||||
assertEquals(1, diagnostics.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testChangingSeverityOfFindPublicBeanMethodInConfigClass() throws Exception {
|
||||
String docUri = directory.toPath().resolve("src/main/java/org/test/BeanMethodNotPublic.java").toUri().toString();
|
||||
|
||||
PublishDiagnosticsParams diagnosticsMessage = harness.getDiagnostics(docUri);
|
||||
List<Diagnostic> diagnostics = diagnosticsMessage.getDiagnostics();
|
||||
|
||||
Diagnostic diagnostic = diagnostics.get(0);
|
||||
assertEquals(Boot2JavaProblemType.JAVA_PUBLIC_BEAN_METHOD.getCode(), diagnostic.getCode().getLeft());
|
||||
assertEquals(1, diagnostics.size());
|
||||
assertEquals(DiagnosticSeverity.Hint, diagnostic.getSeverity());
|
||||
|
||||
String changedSettings = "{\"spring-boot\": {\"ls\": {\"problem\": {\"boot2\": {\"JAVA_PUBLIC_BEAN_METHOD\": \"ERROR\"}}}}}";
|
||||
JsonElement settingsAsJson = new Gson().fromJson(changedSettings, JsonElement.class);
|
||||
Settings settings = new Settings(settingsAsJson);
|
||||
|
||||
harness.changeConfiguration(settings);
|
||||
|
||||
CompletableFuture<Void> initProject = indexer.waitOperation();
|
||||
initProject.get(5, TimeUnit.SECONDS);
|
||||
|
||||
diagnosticsMessage = harness.getDiagnostics(docUri);
|
||||
diagnostics = diagnosticsMessage.getDiagnostics();
|
||||
|
||||
diagnostic = diagnostics.get(0);
|
||||
assertEquals(Boot2JavaProblemType.JAVA_PUBLIC_BEAN_METHOD.getCode(), diagnostic.getCode().getLeft());
|
||||
assertEquals(1, diagnostics.size());
|
||||
assertEquals(DiagnosticSeverity.Error, diagnostic.getSeverity());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPublishEmptyDiagnosticsWhenNoProblemsAreFound() throws Exception {
|
||||
String docUri = directory.toPath().resolve("src/main/java/org/test/BeanClass1.java").toUri().toString();
|
||||
|
||||
Reference in New Issue
Block a user