Boot Language Server obeys configured problem severities
This commit is contained in:
@@ -39,9 +39,6 @@ public class BootJavaConfig implements InitializingBean {
|
||||
public static final boolean VALIDAITON_SPEL_EXPRESSIONS_ENABLED_DEFAULT = true;
|
||||
|
||||
|
||||
//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>();
|
||||
@@ -140,4 +137,8 @@ public class BootJavaConfig implements InitializingBean {
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
workspace.onDidChangeConfiguraton(this::handleConfigurationChange);
|
||||
}
|
||||
|
||||
public Settings getRawSettings() {
|
||||
return settings;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2020 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
|
||||
* https://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.boot.app;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.ide.vscode.commons.languageserver.reconcile.DiagnosticSeverityProvider;
|
||||
import org.springframework.ide.vscode.commons.languageserver.reconcile.ProblemSeverity;
|
||||
import org.springframework.ide.vscode.commons.languageserver.reconcile.ReconcileProblem;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.Settings;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer;
|
||||
import org.springframework.ide.vscode.commons.util.Assert;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class ProblemSeverityConfigurer implements InitializingBean {
|
||||
|
||||
@Autowired
|
||||
private SimpleLanguageServer server;
|
||||
|
||||
@Autowired
|
||||
private BootJavaConfig config;
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
config.addListener((x) -> configChanged());
|
||||
configChanged();
|
||||
}
|
||||
|
||||
private void configChanged() {
|
||||
Settings settings = config.getRawSettings();
|
||||
settings = settings.navigate("spring-boot", "ls", "problem");
|
||||
|
||||
Map<String, ProblemSeverity> severityOverrides = new HashMap<>();
|
||||
for (String editorType : settings.keys()) {
|
||||
Settings problemConf = settings.navigate(editorType);
|
||||
for (String code : problemConf.keys()) {
|
||||
String severity = problemConf.getString(code);
|
||||
System.out.println(code+" => "+severity);
|
||||
Assert.isLegal(!severityOverrides.containsKey(code), "Multpile entries for problem type "+code);
|
||||
severityOverrides.put(code, ProblemSeverity.valueOf(severity));
|
||||
}
|
||||
}
|
||||
server.setDiagnosticSeverityProvider((ReconcileProblem problem) -> {
|
||||
ProblemSeverity severity = severityOverrides.get(problem.getType().getCode());
|
||||
if (severity==null) {
|
||||
severity = problem.getType().getDefaultSeverity();
|
||||
}
|
||||
return DiagnosticSeverityProvider.diagnosticSeverity(severity);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -45,5 +45,5 @@ public class SpringPropertyProblem extends ReconcileProblemImpl {
|
||||
public void setPropertyName(String name) {
|
||||
propertyName = name;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user