Skip to content

Commit e285e3a

Browse files
committed
GH-1345: use diagnostics tags from lsp protocol to mark unnecessary and deprecated things accordingly
1 parent b4292f6 commit e285e3a

File tree

15 files changed

+238
-93
lines changed

15 files changed

+238
-93
lines changed

headless-services/commons/commons-language-server/src/main/java/org/springframework/ide/vscode/commons/languageserver/reconcile/BadWordReconcileEngine.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2016-2017 Pivotal, Inc.
2+
* Copyright (c) 2016, 2024 Pivotal, Inc.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -11,6 +11,9 @@
1111

1212
package org.springframework.ide.vscode.commons.languageserver.reconcile;
1313

14+
import java.util.List;
15+
16+
import org.eclipse.lsp4j.DiagnosticTag;
1417
import org.springframework.ide.vscode.commons.util.text.IDocument;
1518

1619
/**
@@ -51,6 +54,11 @@ public String getLabel() {
5154
public ProblemCategory getCategory() {
5255
return null;
5356
}
57+
58+
@Override
59+
public List<DiagnosticTag> getTags() {
60+
return null;
61+
}
5462
}
5563

5664
private final String[] BADWORDS = {

headless-services/commons/commons-language-server/src/main/java/org/springframework/ide/vscode/commons/languageserver/reconcile/ProblemType.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2016-2017 Pivotal, Inc.
2+
* Copyright (c) 2016, 2024 Pivotal, Inc.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -11,6 +11,10 @@
1111

1212
package org.springframework.ide.vscode.commons.languageserver.reconcile;
1313

14+
import java.util.List;
15+
16+
import org.eclipse.lsp4j.DiagnosticTag;
17+
1418
/**
1519
* Besides the methods below, the only hard requirement for a 'problem type' is
1620
* that it is a unique object that is not 'equals' to any other object.
@@ -29,4 +33,5 @@ public interface ProblemType {
2933
String getLabel();
3034
String getDescription();
3135
ProblemCategory getCategory();
36+
List<DiagnosticTag> getTags();
3237
}

headless-services/commons/commons-language-server/src/main/java/org/springframework/ide/vscode/commons/languageserver/reconcile/ProblemTypes.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2017 Pivotal, Inc.
2+
* Copyright (c) 2017, 2024 Pivotal, Inc.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -10,6 +10,10 @@
1010
*******************************************************************************/
1111
package org.springframework.ide.vscode.commons.languageserver.reconcile;
1212

13+
import java.util.List;
14+
15+
import org.eclipse.lsp4j.DiagnosticTag;
16+
1317
public class ProblemTypes {
1418

1519
/**
@@ -24,7 +28,7 @@ public class ProblemTypes {
2428
* @return A newly create problem type.
2529
*/
2630
@Deprecated
27-
public static ProblemType create(String typeName, ProblemSeverity defaultSeverity, ProblemCategory category) {
31+
public static ProblemType create(String typeName, ProblemSeverity defaultSeverity, ProblemCategory category, List<DiagnosticTag> tags) {
2832
return new ProblemType() {
2933
@Override
3034
public String toString() {
@@ -50,6 +54,10 @@ public String getLabel() {
5054
public ProblemCategory getCategory() {
5155
return category;
5256
}
57+
@Override
58+
public List<DiagnosticTag> getTags() {
59+
return tags;
60+
}
5361
};
5462
}
5563

headless-services/commons/commons-language-server/src/main/java/org/springframework/ide/vscode/commons/languageserver/util/SimpleLanguageServer.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,10 +850,14 @@ public void accept(ReconcileProblem problem) {
850850
Diagnostic d = new Diagnostic();
851851
d.setCode(problem.getCode());
852852
d.setMessage(problem.getMessage());
853+
853854
Range rng = docRef.get().toRange(problem.getOffset(), problem.getLength());
854855
d.setRange(rng);
856+
855857
d.setSeverity(severity);
856858
d.setSource(getServer().EXTENSION_ID);
859+
d.setTags(problem.getType().getTags());
860+
857861
List<QuickfixData<?>> fixes = problem.getQuickfixes();
858862

859863
// Copy original diagnsotic without the data field to avoid stackoverflow is hashCode() method call

headless-services/commons/commons-yaml/src/main/java/org/springframework/ide/vscode/commons/yaml/reconcile/YamlSchemaProblems.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.util.stream.Collectors;
1616
import java.util.stream.Stream;
1717

18+
import org.eclipse.lsp4j.DiagnosticTag;
1819
import org.springframework.ide.vscode.commons.languageserver.quickfix.Quickfix.QuickfixData;
1920
import org.springframework.ide.vscode.commons.languageserver.quickfix.QuickfixType;
2021
import org.springframework.ide.vscode.commons.languageserver.reconcile.ProblemCategory;
@@ -53,8 +54,8 @@ public class YamlSchemaProblems {
5354

5455
public static final ProblemType SYNTAX_PROBLEM = problemType("YamlSyntaxProblem", CATEGORY);
5556
public static final ProblemType SCHEMA_PROBLEM = problemType("YamlSchemaProblem", CATEGORY);
56-
public static final ProblemType DEPRECATED_PROPERTY = problemType("DeprecatedProperty", ProblemSeverity.WARNING, CATEGORY);
57-
public static final ProblemType DEPRECATED_VALUE = problemType("DeprecatedValue", ProblemSeverity.WARNING, CATEGORY);
57+
public static final ProblemType DEPRECATED_PROPERTY = problemType("DeprecatedProperty", ProblemSeverity.WARNING, CATEGORY, List.of(DiagnosticTag.Deprecated));
58+
public static final ProblemType DEPRECATED_VALUE = problemType("DeprecatedValue", ProblemSeverity.WARNING, CATEGORY, List.of(DiagnosticTag.Deprecated));
5859
public static final ProblemType MISSING_PROPERTY = problemType("MissingProperty", ProblemSeverity.ERROR, CATEGORY);
5960
public static final ProblemType EXTRA_PROPERTY = problemType("ExtraProperty", ProblemSeverity.ERROR, CATEGORY);
6061
public static final ProblemType EMPTY_OPTIONAL_STRING = problemType("EmptyOptionalString", ProblemSeverity.WARNING, CATEGORY);
@@ -63,8 +64,12 @@ public class YamlSchemaProblems {
6364
MISSING_PROPERTY, EXTRA_PROPERTY
6465
);
6566

67+
public static ProblemType problemType(final String typeName, ProblemSeverity defaultSeverity, ProblemCategory category, List<DiagnosticTag> tags) {
68+
return ProblemTypes.create(typeName, defaultSeverity, category, tags);
69+
}
70+
6671
public static ProblemType problemType(final String typeName, ProblemSeverity defaultSeverity, ProblemCategory category) {
67-
return ProblemTypes.create(typeName, defaultSeverity, category);
72+
return problemType(typeName, defaultSeverity, category, null);
6873
}
6974

7075
public static ProblemType problemType(final String typeName, ProblemCategory category) {
Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2022, 2023 VMware, Inc.
2+
* Copyright (c) 2022, 2024 VMware, Inc.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -12,49 +12,47 @@
1212

1313
import static org.springframework.ide.vscode.commons.languageserver.reconcile.ProblemSeverity.*;
1414

15+
import java.util.List;
16+
17+
import org.eclipse.lsp4j.DiagnosticTag;
1518
import org.springframework.ide.vscode.boot.common.SpringProblemCategories;
1619
import org.springframework.ide.vscode.commons.languageserver.reconcile.ProblemCategory;
1720
import org.springframework.ide.vscode.commons.languageserver.reconcile.ProblemSeverity;
1821
import org.springframework.ide.vscode.commons.languageserver.reconcile.ProblemType;
1922

2023
public enum Boot2JavaProblemType implements ProblemType {
2124

22-
JAVA_AUTOWIRED_CONSTRUCTOR(WARNING, "Unnecessary `@Autowired` over the only constructor", "Unnecessary `@Autowired`"),
23-
24-
JAVA_PUBLIC_BEAN_METHOD(HINT, "Public modifier on `@Bean` method. They no longer have to be public visibility to be usable by Spring.", "public `@Bean` method"),
25-
26-
JAVA_TEST_SPRING_EXTENSION(WARNING, "`@SpringBootTest` and all test slice annotations already applies `@SpringExtension` as of Spring Boot 2.1.0.", "Unnecessary `@SpringExtension`"),
27-
25+
JAVA_AUTOWIRED_CONSTRUCTOR(WARNING, "Unnecessary `@Autowired` over the only constructor", "Unnecessary `@Autowired`", List.of(DiagnosticTag.Unnecessary)),
26+
JAVA_PUBLIC_BEAN_METHOD(HINT, "Public modifier on `@Bean` method. They no longer have to be public visibility to be usable by Spring.", "public `@Bean` method", List.of(DiagnosticTag.Unnecessary)),
27+
JAVA_TEST_SPRING_EXTENSION(WARNING, "`@SpringBootTest` and all test slice annotations already applies `@SpringExtension` as of Spring Boot 2.1.0.", "Unnecessary `@SpringExtension`", List.of(DiagnosticTag.Unnecessary)),
2828
JAVA_CONSTRUCTOR_PARAMETER_INJECTION(IGNORE, "Use constructor parameter injection", "Use constructor parameter injection"),
29-
3029
JAVA_PRECISE_REQUEST_MAPPING(HINT, "Use precise mapping annotation, i.e. '@GetMapping', '@PostMapping', etc.", "Use precise mapping annotation, i.e. '@GetMapping', '@PostMapping', etc."),
31-
32-
JAVA_REPOSITORY(WARNING, "Unnecessary `@Repository`", "Unnecessary `@Repository`"),
33-
30+
JAVA_REPOSITORY(WARNING, "Unnecessary `@Repository`", "Unnecessary `@Repository`", List.of(DiagnosticTag.Unnecessary)),
3431
JAVA_LAMBDA_DSL(INFO, "Consider switching to Lambda DSL syntax", "Switch to Lambda DSL syntax"),
35-
3632
MISSING_CONFIGURATION_ANNOTATION(WARNING, "Class likely missing '@Configuration' annotation, i.e. has Bean methods but no '@Configuration' annotation", "Missing '@Configuration'"),
37-
3833
HTTP_SECURITY_AUTHORIZE_HTTP_REQUESTS(WARNING, "'HttpSecurity.authroizeRequests(...)' API and related classes are to be deprecated use new `authorizeHttpRequests(...) and related classes", "Usage of old 'HttpSecurity.authroizeRequests(...)' API"),
39-
4034
WEB_SECURITY_CONFIGURER_ADAPTER(WARNING, "'WebSecurityConfigurerAdapter' is removed in Spring-Security 6.x. Refactor classes extending the 'WebSecurityConfigurerAdapter' into 'Configuration' beans and methods into 'Bean' definitions ", "Replace usage of 'WebSecurityConfigurerAdapter' as this class to be removed in Security 6.x"),
41-
4235
DOMAIN_ID_FOR_REPOSITORY(ERROR, "Invalid Domain ID type for Spring Data Repository", "Invalid Domain ID Type for Spring Data Repository"),
43-
44-
WEB_ANNOTATION_NAMES(HINT, "Web annotation names are unnecessary when it is the same as method parameter name", "Implicit web annotations names");
36+
WEB_ANNOTATION_NAMES(HINT, "Web annotation names are unnecessary when it is the same as method parameter name", "Implicit web annotations names", List.of(DiagnosticTag.Unnecessary));
4537

4638
private final ProblemSeverity defaultSeverity;
47-
private String description;
39+
private final String description;
4840
private String label;
41+
private List<DiagnosticTag> tags;
4942

50-
private Boot2JavaProblemType(ProblemSeverity defaultSeverity, String description) {
51-
this(defaultSeverity, description, null);
52-
}
53-
54-
private Boot2JavaProblemType(ProblemSeverity defaultSeverity, String description, String label) {
43+
private Boot2JavaProblemType(ProblemSeverity defaultSeverity, String description, String label, List<DiagnosticTag> tags) {
5544
this.description = description;
5645
this.defaultSeverity = defaultSeverity;
5746
this.label = label;
47+
this.tags = tags;
48+
}
49+
50+
private Boot2JavaProblemType(ProblemSeverity defaultSeverity, String description, String label) {
51+
this(defaultSeverity, description, label, null);
52+
}
53+
54+
private Boot2JavaProblemType(ProblemSeverity defaultSeverity, String description) {
55+
this(defaultSeverity, description, null);
5856
}
5957

6058
@Override
@@ -63,7 +61,7 @@ public ProblemSeverity getDefaultSeverity() {
6361
}
6462

6563
public String getLabel() {
66-
if (label==null) {
64+
if (label == null) {
6765
label = createDefaultLabel();
6866
}
6967
return label;
@@ -89,4 +87,9 @@ public ProblemCategory getCategory() {
8987
return SpringProblemCategories.BOOT_2;
9088
}
9189

90+
@Override
91+
public List<DiagnosticTag> getTags() {
92+
return tags;
93+
}
94+
9295
}

headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/Boot3JavaProblemType.java

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2020, 2023 Pivotal, Inc.
2+
* Copyright (c) 2020, 2024 Pivotal, Inc.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -12,6 +12,9 @@
1212

1313
import static org.springframework.ide.vscode.commons.languageserver.reconcile.ProblemSeverity.ERROR;
1414

15+
import java.util.List;
16+
17+
import org.eclipse.lsp4j.DiagnosticTag;
1518
import org.springframework.ide.vscode.boot.common.SpringProblemCategories;
1619
import org.springframework.ide.vscode.commons.languageserver.reconcile.ProblemCategory;
1720
import org.springframework.ide.vscode.commons.languageserver.reconcile.ProblemSeverity;
@@ -24,23 +27,27 @@
2427
public enum Boot3JavaProblemType implements ProblemType {
2528

2629
JAVA_TYPE_NOT_SUPPORTED(ERROR, "Type no supported as of Spring Boot 3", "Type not supported as of Spring Boot 3"),
27-
2830
FACTORIES_KEY_NOT_SUPPORTED(ERROR, "Spring factories key not supported", "Spring factories key not supported"),
29-
3031
MODULITH_TYPE_REF_VIOLATION(ERROR, "Modulith restricted type reference", "Modulith restricted type reference");
3132

3233
private final ProblemSeverity defaultSeverity;
33-
private String description;
34+
private final String description;
3435
private String label;
36+
private final List<DiagnosticTag> tags;
3537

36-
private Boot3JavaProblemType(ProblemSeverity defaultSeverity, String description) {
37-
this(defaultSeverity, description, null);
38-
}
39-
40-
private Boot3JavaProblemType(ProblemSeverity defaultSeverity, String description, String label) {
38+
private Boot3JavaProblemType(ProblemSeverity defaultSeverity, String description, String label, List<DiagnosticTag> tags) {
4139
this.description = description;
4240
this.defaultSeverity = defaultSeverity;
4341
this.label = label;
42+
this.tags = tags;
43+
}
44+
45+
private Boot3JavaProblemType(ProblemSeverity defaultSeverity, String description, String label) {
46+
this(defaultSeverity, description, label, null);
47+
}
48+
49+
private Boot3JavaProblemType(ProblemSeverity defaultSeverity, String description) {
50+
this(defaultSeverity, description, null);
4451
}
4552

4653
@Override
@@ -49,7 +56,7 @@ public ProblemSeverity getDefaultSeverity() {
4956
}
5057

5158
public String getLabel() {
52-
if (label==null) {
59+
if (label == null) {
5360
label = createDefaultLabel();
5461
}
5562
return label;
@@ -74,5 +81,10 @@ public String getCode() {
7481
public ProblemCategory getCategory() {
7582
return SpringProblemCategories.BOOT_3;
7683
}
84+
85+
@Override
86+
public List<DiagnosticTag> getTags() {
87+
return tags;
88+
}
7789

7890
}

headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/SpelProblemType.java

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2022 VMware, Inc.
2+
* Copyright (c) 2022, 2024 VMware, Inc.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -12,6 +12,9 @@
1212

1313
import static org.springframework.ide.vscode.commons.languageserver.reconcile.ProblemSeverity.ERROR;
1414

15+
import java.util.List;
16+
17+
import org.eclipse.lsp4j.DiagnosticTag;
1518
import org.springframework.ide.vscode.boot.common.SpringProblemCategories;
1619
import org.springframework.ide.vscode.commons.languageserver.reconcile.ProblemCategory;
1720
import org.springframework.ide.vscode.commons.languageserver.reconcile.ProblemSeverity;
@@ -23,17 +26,23 @@ public enum SpelProblemType implements ProblemType {
2326
PROPERTY_PLACE_HOLDER_SYNTAX(ERROR, "Property place holder raised a ParseException", "Property Place Holder Syntax");
2427

2528
private final ProblemSeverity defaultSeverity;
26-
private String description;
29+
private final String description;
2730
private String label;
31+
private final List<DiagnosticTag> tags;
2832

29-
private SpelProblemType(ProblemSeverity defaultSeverity, String description) {
30-
this(defaultSeverity, description, null);
31-
}
32-
33-
private SpelProblemType(ProblemSeverity defaultSeverity, String description, String label) {
33+
private SpelProblemType(ProblemSeverity defaultSeverity, String description, String label, List<DiagnosticTag> tags) {
3434
this.description = description;
3535
this.defaultSeverity = defaultSeverity;
3636
this.label = label;
37+
this.tags = tags;
38+
}
39+
40+
private SpelProblemType(ProblemSeverity defaultSeverity, String description, String label) {
41+
this(defaultSeverity, description, label, null);
42+
}
43+
44+
private SpelProblemType(ProblemSeverity defaultSeverity, String description) {
45+
this(defaultSeverity, description, null);
3746
}
3847

3948
@Override
@@ -42,7 +51,7 @@ public ProblemSeverity getDefaultSeverity() {
4251
}
4352

4453
public String getLabel() {
45-
if (label==null) {
54+
if (label == null) {
4655
label = createDefaultLabel();
4756
}
4857
return label;
@@ -67,4 +76,9 @@ public String getCode() {
6776
public ProblemCategory getCategory() {
6877
return SpringProblemCategories.SPEL;
6978
}
79+
80+
@Override
81+
public List<DiagnosticTag> getTags() {
82+
return tags;
83+
}
7084
}

0 commit comments

Comments
 (0)