Skip to content

Commit 00f52fa

Browse files
author
Alexander Chen
committed
Added diagnostic for deprecated with section and CodeAction to use let
Signed-off-by: Alexander Chen <alchen@redhat.com>
1 parent 3ff7394 commit 00f52fa

File tree

5 files changed

+70
-16
lines changed

5 files changed

+70
-16
lines changed

qute.ls/com.redhat.qute.ls/src/main/java/com/redhat/qute/parser/template/sections/WithSection.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@
1818

1919
/**
2020
* With section AST node.
21-
*
21+
*
2222
* <code>
2323
{#with item.parent}
24-
<h1>{name}</h1>
25-
<p>{description}</p>
24+
<h1>{name}</h1>
25+
<p>{description}</p>
2626
{/with}
2727
* </code>
28-
*
28+
*
2929
* @author Angelo ZERR
30-
*
30+
*
3131
* @see https://quarkus.io/guides/qute-reference#with_section
3232
*
3333
*/

qute.ls/com.redhat.qute.ls/src/main/java/com/redhat/qute/services/QuteCodeActions.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050

5151
/**
5252
* Qute code actions support.
53-
*
53+
*
5454
* @author Angelo ZERR
5555
*
5656
*/
@@ -72,6 +72,8 @@ class QuteCodeActions {
7272

7373
private static final String EXCLUDED_VALIDATION_TITLE = "Exclude this file from validation.";
7474

75+
private static final String QUTE_DEPRICATED_WITH_SECTION = "Replace `with` with `let`.";
76+
7577
public CompletableFuture<List<CodeAction>> doCodeActions(Template template, CodeActionContext context, Range range,
7678
SharedSettings sharedSettings) {
7779
List<CodeAction> codeActions = new ArrayList<>();
@@ -186,15 +188,28 @@ private static void doCodeActionToDisableValidation(Template template, List<Diag
186188
codeActions.add(disableValidationForTemplateQuickFix);
187189
}
188190

191+
/**
192+
* Create CodeAction for deprecated `with` Qute syntax.
193+
*
194+
* @param template the Qute template.
195+
* @param diagnostic the diagnostic list that this CodeAction will fix.
196+
* @param codeActions the list of CodeActions to perform.
197+
*
198+
*/
199+
private void doCodeActionsForDeprecatedWithSection(Template template, Diagnostic diagnostic,
200+
List<CodeAction> codeActions) {
201+
202+
}
203+
189204
/**
190205
* Create the configuration update (done on client side) quick fix.
191-
*
206+
*
192207
* @param title the displayed name of the QuickFix.
193208
* @param sectionName the section name of the settings to update.
194209
* @param item the section value of the settings to update.
195210
* @param editType the configuration edit type.
196211
* @param diagnostic the diagnostic list that this CodeAction will fix.
197-
*
212+
*
198213
* @return the configuration update (done on client side) quick fix.
199214
*/
200215
private static CodeAction createConfigurationUpdateCodeAction(String title, String scopeUri, String sectionName,

qute.ls/com.redhat.qute.ls/src/main/java/com/redhat/qute/services/QuteDiagnostics.java

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
package com.redhat.qute.services;
1313

1414
import static com.redhat.qute.services.diagnostics.DiagnosticDataFactory.createDiagnostic;
15+
import static com.redhat.qute.services.diagnostics.DiagnosticDataFactory.createDiagnosticWithTags;
1516

1617
import java.nio.file.Files;
1718
import java.nio.file.Path;
@@ -26,6 +27,7 @@
2627

2728
import org.eclipse.lsp4j.Diagnostic;
2829
import org.eclipse.lsp4j.DiagnosticSeverity;
30+
import org.eclipse.lsp4j.DiagnosticTag;
2931
import org.eclipse.lsp4j.Range;
3032
import org.eclipse.lsp4j.jsonrpc.CancelChecker;
3133

@@ -54,6 +56,7 @@
5456
import com.redhat.qute.parser.template.Template;
5557
import com.redhat.qute.parser.template.sections.IncludeSection;
5658
import com.redhat.qute.parser.template.sections.LoopSection;
59+
import com.redhat.qute.parser.template.sections.WithSection;
5760
import com.redhat.qute.project.JavaMemberResult;
5861
import com.redhat.qute.project.QuteProject;
5962
import com.redhat.qute.project.datamodel.JavaDataModelCache;
@@ -246,6 +249,9 @@ private void validateDataModel(Node parent, Template template, ResolvingJavaType
246249
case INCLUDE:
247250
validateIncludeSection((IncludeSection) section, diagnostics);
248251
break;
252+
case WITH:
253+
validateWithSection((WithSection) section, diagnostics);
254+
break;
249255
default:
250256
validateSectionTag(section, template, resolvingJavaTypeContext, diagnostics);
251257
}
@@ -345,6 +351,24 @@ private static void validateIncludeSection(IncludeSection includeSection, List<D
345351
}
346352
}
347353

354+
/**
355+
* Report that `#with` section is deprecated.
356+
*
357+
* @param withSection the with section
358+
* @param diagnostics the diagnostics to fill
359+
*/
360+
private static void validateWithSection(WithSection withSection, List<Diagnostic> diagnostics) {
361+
if (withSection != null) {
362+
List<DiagnosticTag> tags = Collections.singletonList(DiagnosticTag.Deprecated);
363+
// Section withTag = new Section("with", withSection.getStartTagNameOpenOffset(),
364+
// withSection.getStartTagNameCloseOffset());
365+
Range range = QutePositionUtility.selectStartTagName(withSection);
366+
Diagnostic diagnostic = createDiagnosticWithTags(range, DiagnosticSeverity.Warning,
367+
QuteErrorCode.DeprecatedWithSection, tags);
368+
diagnostics.add(diagnostic);
369+
}
370+
}
371+
348372
private ResolvedJavaTypeInfo validateExpression(Expression expression, Section ownerSection, Template template,
349373
ResolutionContext resolutionContext, ResolvingJavaTypeContext resolvingJavaTypeContext,
350374
List<Diagnostic> diagnostics) {
@@ -391,7 +415,7 @@ private ResolvedJavaTypeInfo validateExpressionParts(Parts parts, Section ownerS
391415
ResolvedJavaTypeInfo resolvedJavaType = null;
392416
String namespace = null;
393417
for (int i = 0; i < parts.getChildCount(); i++) {
394-
Part current = ((Part) parts.getChild(i));
418+
Part current = (parts.getChild(i));
395419

396420
if (current.isLast()) {
397421
// It's the last part, check if it is not ended with '.'
@@ -586,7 +610,7 @@ private ResolvedJavaTypeInfo validateObjectPart(ObjectPart objectPart, Section o
586610

587611
/**
588612
* Validate the given property, method part.
589-
*
613+
*
590614
* @param part the property, method part to validate.
591615
* @param ownerSection the owner section and null otherwise.
592616
* @param template the template.
@@ -596,7 +620,7 @@ private ResolvedJavaTypeInfo validateObjectPart(ObjectPart objectPart, Section o
596620
* @param iterableOfType the iterable of type.
597621
* @param diagnostics the diagnostic list to fill.
598622
* @param resolvingJavaTypeContext the resolving Java type context.
599-
*
623+
*
600624
* @return the Java type returned by the member part and null otherwise.
601625
*/
602626
private ResolvedJavaTypeInfo validateMemberPart(Part part, Section ownerSection, Template template,
@@ -617,7 +641,7 @@ private ResolvedJavaTypeInfo validateMemberPart(Part part, Section ownerSection,
617641

618642
/**
619643
* Validate the given property part.
620-
*
644+
*
621645
* @param part the property part to validate.
622646
* @param ownerSection the owner section and null otherwise.
623647
* @param template the template.
@@ -627,7 +651,7 @@ private ResolvedJavaTypeInfo validateMemberPart(Part part, Section ownerSection,
627651
* @param iterableOfType the iterable of type.
628652
* @param diagnostics the diagnostic list to fill.
629653
* @param resolvingJavaTypeContext the resolving Java type context.
630-
*
654+
*
631655
* @return the Java type returned by the member part and null otherwise.
632656
*/
633657
private ResolvedJavaTypeInfo validatePropertyPart(PropertyPart part, Section ownerSection, Template template,
@@ -650,7 +674,7 @@ private ResolvedJavaTypeInfo validatePropertyPart(PropertyPart part, Section own
650674

651675
/**
652676
* Validate the given method part.
653-
*
677+
*
654678
* @param part the method part to validate.
655679
* @param ownerSection the owner section and null otherwise.
656680
* @param template the template.
@@ -660,7 +684,7 @@ private ResolvedJavaTypeInfo validatePropertyPart(PropertyPart part, Section own
660684
* @param iterableOfType the iterable of type.
661685
* @param diagnostics the diagnostic list to fill.
662686
* @param resolvingJavaTypeContext the resolving Java type context.
663-
*
687+
*
664688
* @return the Java type returned by the member part and null otherwise.
665689
*/
666690
private ResolvedJavaTypeInfo validateMethodPart(MethodPart methodPart, Section ownerSection, Template template,

qute.ls/com.redhat.qute.ls/src/main/java/com/redhat/qute/services/diagnostics/DiagnosticDataFactory.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@
1616
import static com.redhat.qute.services.diagnostics.QuteDiagnosticContants.DIAGNOSTIC_DATA_TAG;
1717
import static com.redhat.qute.services.diagnostics.QuteDiagnosticContants.QUTE_SOURCE;
1818

19+
import java.util.List;
20+
1921
import org.eclipse.lsp4j.Diagnostic;
2022
import org.eclipse.lsp4j.DiagnosticSeverity;
23+
import org.eclipse.lsp4j.DiagnosticTag;
2124
import org.eclipse.lsp4j.Range;
2225

2326
import com.google.gson.JsonObject;
@@ -55,4 +58,13 @@ public static Diagnostic createDiagnostic(Range range, String message, Diagnosti
5558
errorCode != null ? errorCode.getCode() : null);
5659
return diagnostic;
5760
}
61+
62+
public static Diagnostic createDiagnosticWithTags(Range range, DiagnosticSeverity severity,
63+
IQuteErrorCode errorCode, List<DiagnosticTag> tags, Object... arguments) {
64+
String message = errorCode.getMessage(arguments);
65+
Diagnostic diagnostic = new Diagnostic(range, message, severity, QUTE_SOURCE,
66+
errorCode != null ? errorCode.getCode() : null);
67+
diagnostic.setTags(tags);
68+
return diagnostic;
69+
}
5870
}

qute.ls/com.redhat.qute.ls/src/main/java/com/redhat/qute/services/diagnostics/QuteErrorCode.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ public enum QuteErrorCode implements IQuteErrorCode {
4545

4646
UndefinedSectionTag("No section helper found for `{0}`."), //
4747

48-
SyntaxError("Syntax error: `{0}`.");
48+
SyntaxError("Syntax error: `{0}`."),
49+
50+
// Error code for deprecated #with section
51+
DeprecatedWithSection("`with` is deprecated. Use `let` instead.");
4952

5053
private final String rawMessage;
5154

0 commit comments

Comments
 (0)