Preference page for boot-ls Java problem severities

This commit is contained in:
Kris De Volder
2020-10-05 11:18:33 -07:00
parent d1d31e2a7c
commit d2d6de5123
9 changed files with 121 additions and 4 deletions

View File

@@ -143,6 +143,12 @@
class="org.springframework.tooling.boot.ls.prefs.ApplicationYamlEditorProblemSeverityPrefsPage"
id="org.springframework.tooling.boot.ls.prefs.ApplicationYamlEditorProblemSeverityPrefsPage">
</page>
<page
name="Java Editor"
category="org.springframework.tooling.boot.ls.preferences"
class="org.springframework.tooling.boot.ls.prefs.SpringJavaProblemSeverityPrefsPage"
id="org.springframework.tooling.boot.ls.prefs.SpringJavaProblemSeverityPrefsPage">
</page>
</extension>

View File

@@ -0,0 +1,32 @@
/*******************************************************************************
* 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.tooling.boot.ls.prefs;
import java.io.IOException;
import org.springframework.ide.eclipse.editor.support.preferences.ProblemSeverityPreferencesUtil;
import org.springframework.ide.eclipse.editor.support.preferences.ProblemSeverityPreferityPageFromMetadata;
import org.springframework.tooling.boot.ls.BootLanguageServerPlugin;
public class SpringJavaProblemSeverityPrefsPage extends ProblemSeverityPreferityPageFromMetadata {
public static final ProblemSeverityPreferencesUtil util = new ProblemSeverityPreferencesUtil("problem.java.");
public SpringJavaProblemSeverityPrefsPage() throws IOException {
super(util, LanguageServerProblemTypesMetadata.load().get("java"));
}
@Override
protected String getPluginId() {
return BootLanguageServerPlugin.PLUGIN_ID;
}
}

View File

@@ -0,0 +1,69 @@
/*******************************************************************************
* 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.java;
import org.springframework.ide.vscode.commons.languageserver.reconcile.ProblemSeverity;
import org.springframework.ide.vscode.commons.languageserver.reconcile.ProblemType;
import org.springframework.ide.vscode.commons.util.Assert;
import static org.springframework.ide.vscode.commons.languageserver.reconcile.ProblemSeverity.ERROR;;
/**
* This enum is supposed to represent *all* the different types of problems SpringBoot language server
* may detect in Java code.
*/
public enum SpringJavaProblemType implements ProblemType {
JAVA_SPEL_EXPRESSION_SYNTAX(ERROR, "SpEL parser raised a ParseException", "SpEL Expression Syntax");
private final ProblemSeverity defaultSeverity;
private String description;
private String label;
private SpringJavaProblemType(ProblemSeverity defaultSeverity, String description) {
this(defaultSeverity, description, null);
}
private SpringJavaProblemType(ProblemSeverity defaultSeverity, String description, String label) {
this.description = description;
this.defaultSeverity = defaultSeverity;
this.label = label;
Assert.isLegal(name().startsWith("JAVA_"));
}
@Override
public ProblemSeverity getDefaultSeverity() {
return defaultSeverity;
}
public String getLabel() {
if (label==null) {
label = createDefaultLabel();
}
return label;
}
@Override
public String getDescription() {
return description;
}
private String createDefaultLabel() {
String label = this.toString().substring(5).toLowerCase().replace('_', ' ');
return Character.toUpperCase(label.charAt(0)) + label.substring(1);
}
@Override
public String getCode() {
return name();
}
}

View File

@@ -19,7 +19,6 @@ import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.Annotation;
import org.eclipse.jdt.core.dom.ITypeBinding;
import org.eclipse.jdt.core.dom.NodeFinder;
import org.springframework.ide.vscode.boot.java.BootJavaLanguageServerComponents;
import org.springframework.ide.vscode.boot.java.snippets.JavaSnippetManager;
import org.springframework.ide.vscode.boot.java.utils.CompilationUnitCache;
import org.springframework.ide.vscode.commons.languageserver.completion.ICompletionEngine;

View File

@@ -12,6 +12,7 @@ package org.springframework.ide.vscode.boot.java.handlers;
import org.springframework.expression.ParseException;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.ide.vscode.boot.java.SpringJavaProblemType;
import org.springframework.ide.vscode.commons.languageserver.reconcile.IProblemCollector;
import org.springframework.ide.vscode.commons.languageserver.reconcile.ProblemSeverity;
import org.springframework.ide.vscode.commons.languageserver.reconcile.ProblemTypes;
@@ -57,7 +58,7 @@ public class SpelExpressionReconciler implements Reconciler {
private void createProblem(String spelExpression, String message, int startPosition, int position, IProblemCollector problemCollector) {
int start = startPosition + position;
int length = spelExpression.length() - position;
ReconcileProblem problem = new ReconcileProblemImpl(ProblemTypes.create("SpEL Expression Problem", ProblemSeverity.ERROR), message, start, length);
ReconcileProblem problem = new ReconcileProblemImpl(SpringJavaProblemType.JAVA_SPEL_EXPRESSION_SYNTAX, message, start, length);
problemCollector.accept(problem);
}

View File

@@ -42,14 +42,12 @@ import org.springframework.ide.vscode.boot.properties.reconcile.PropertyNavigato
import org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits;
import org.springframework.ide.vscode.commons.languageserver.completion.ICompletionProposal;
import org.springframework.ide.vscode.commons.languageserver.completion.LazyProposalApplier;
import org.springframework.ide.vscode.commons.languageserver.completion.TransformedCompletion;
import org.springframework.ide.vscode.commons.languageserver.util.PrefixFinder;
import org.springframework.ide.vscode.commons.util.BadLocationException;
import org.springframework.ide.vscode.commons.util.CollectionUtil;
import org.springframework.ide.vscode.commons.util.FuzzyMap;
import org.springframework.ide.vscode.commons.util.FuzzyMap.Match;
import org.springframework.ide.vscode.commons.util.FuzzyMatcher;
import org.springframework.ide.vscode.commons.util.Streams;
import org.springframework.ide.vscode.commons.util.StringUtil;
import org.springframework.ide.vscode.commons.util.text.DocumentRegion;
import org.springframework.ide.vscode.commons.util.text.IDocument;

View File

@@ -1,4 +1,12 @@
{
"java": [
{
"code": "JAVA_SPEL_EXPRESSION_SYNTAX",
"label": "SpEL Expression Syntax",
"description": "SpEL parser raised a ParseException",
"defaultSeverity": "ERROR"
}
],
"application-yaml": [
{
"code": "YAML_SYNTAX_ERROR",

View File

@@ -11,6 +11,7 @@
package org.springframework.ide.vscode.boot.test;
import org.junit.jupiter.api.Test;
import org.springframework.ide.vscode.boot.java.SpringJavaProblemType;
import org.springframework.ide.vscode.boot.properties.reconcile.ApplicationPropertiesProblemType;
import org.springframework.ide.vscode.boot.yaml.reconcile.ApplicationYamlProblemType;
@@ -24,6 +25,7 @@ public class ProblemTypesMetadataTest {
ProblemTypesToJson reader = new ProblemTypesToJson().read();
reader.validate("application-properties", ApplicationPropertiesProblemType.values());
reader.validate("application-yaml", ApplicationYamlProblemType.values());
reader.validate("java", SpringJavaProblemType.values());
}
}

View File

@@ -23,6 +23,7 @@ import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.commons.io.FileUtils;
import org.springframework.ide.vscode.boot.java.SpringJavaProblemType;
import org.springframework.ide.vscode.boot.properties.reconcile.ApplicationPropertiesProblemType;
import org.springframework.ide.vscode.boot.yaml.reconcile.ApplicationYamlProblemType;
import org.springframework.ide.vscode.commons.languageserver.reconcile.ProblemType;
@@ -99,6 +100,7 @@ public class ProblemTypesToJson {
ProblemTypesToJson writer = new ProblemTypesToJson();
writer.problemsFor("application-yaml", ApplicationYamlProblemType.values());
writer.problemsFor("application-properties", ApplicationPropertiesProblemType.values());
writer.problemsFor("java", SpringJavaProblemType.values());
writer.dump();
}