Skip to content

Commit

Permalink
Added diagnostic for deprecated with section and CodeAction to use let
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Chen <[email protected]>
  • Loading branch information
Alexander Chen committed Feb 22, 2022
1 parent 3ff7394 commit 00f52fa
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@

/**
* With section AST node.
*
*
* <code>
{#with item.parent}
<h1>{name}</h1>
<p>{description}</p>
<h1>{name}</h1>
<p>{description}</p>
{/with}
* </code>
*
*
* @author Angelo ZERR
*
*
* @see https://quarkus.io/guides/qute-reference#with_section
*
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

/**
* Qute code actions support.
*
*
* @author Angelo ZERR
*
*/
Expand All @@ -72,6 +72,8 @@ class QuteCodeActions {

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

private static final String QUTE_DEPRICATED_WITH_SECTION = "Replace `with` with `let`.";

public CompletableFuture<List<CodeAction>> doCodeActions(Template template, CodeActionContext context, Range range,
SharedSettings sharedSettings) {
List<CodeAction> codeActions = new ArrayList<>();
Expand Down Expand Up @@ -186,15 +188,28 @@ private static void doCodeActionToDisableValidation(Template template, List<Diag
codeActions.add(disableValidationForTemplateQuickFix);
}

/**
* Create CodeAction for deprecated `with` Qute syntax.
*
* @param template the Qute template.
* @param diagnostic the diagnostic list that this CodeAction will fix.
* @param codeActions the list of CodeActions to perform.
*
*/
private void doCodeActionsForDeprecatedWithSection(Template template, Diagnostic diagnostic,
List<CodeAction> codeActions) {

}

/**
* Create the configuration update (done on client side) quick fix.
*
*
* @param title the displayed name of the QuickFix.
* @param sectionName the section name of the settings to update.
* @param item the section value of the settings to update.
* @param editType the configuration edit type.
* @param diagnostic the diagnostic list that this CodeAction will fix.
*
*
* @return the configuration update (done on client side) quick fix.
*/
private static CodeAction createConfigurationUpdateCodeAction(String title, String scopeUri, String sectionName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
package com.redhat.qute.services;

import static com.redhat.qute.services.diagnostics.DiagnosticDataFactory.createDiagnostic;
import static com.redhat.qute.services.diagnostics.DiagnosticDataFactory.createDiagnosticWithTags;

import java.nio.file.Files;
import java.nio.file.Path;
Expand All @@ -26,6 +27,7 @@

import org.eclipse.lsp4j.Diagnostic;
import org.eclipse.lsp4j.DiagnosticSeverity;
import org.eclipse.lsp4j.DiagnosticTag;
import org.eclipse.lsp4j.Range;
import org.eclipse.lsp4j.jsonrpc.CancelChecker;

Expand Down Expand Up @@ -54,6 +56,7 @@
import com.redhat.qute.parser.template.Template;
import com.redhat.qute.parser.template.sections.IncludeSection;
import com.redhat.qute.parser.template.sections.LoopSection;
import com.redhat.qute.parser.template.sections.WithSection;
import com.redhat.qute.project.JavaMemberResult;
import com.redhat.qute.project.QuteProject;
import com.redhat.qute.project.datamodel.JavaDataModelCache;
Expand Down Expand Up @@ -246,6 +249,9 @@ private void validateDataModel(Node parent, Template template, ResolvingJavaType
case INCLUDE:
validateIncludeSection((IncludeSection) section, diagnostics);
break;
case WITH:
validateWithSection((WithSection) section, diagnostics);
break;
default:
validateSectionTag(section, template, resolvingJavaTypeContext, diagnostics);
}
Expand Down Expand Up @@ -345,6 +351,24 @@ private static void validateIncludeSection(IncludeSection includeSection, List<D
}
}

/**
* Report that `#with` section is deprecated.
*
* @param withSection the with section
* @param diagnostics the diagnostics to fill
*/
private static void validateWithSection(WithSection withSection, List<Diagnostic> diagnostics) {
if (withSection != null) {
List<DiagnosticTag> tags = Collections.singletonList(DiagnosticTag.Deprecated);
// Section withTag = new Section("with", withSection.getStartTagNameOpenOffset(),
// withSection.getStartTagNameCloseOffset());
Range range = QutePositionUtility.selectStartTagName(withSection);
Diagnostic diagnostic = createDiagnosticWithTags(range, DiagnosticSeverity.Warning,
QuteErrorCode.DeprecatedWithSection, tags);
diagnostics.add(diagnostic);
}
}

private ResolvedJavaTypeInfo validateExpression(Expression expression, Section ownerSection, Template template,
ResolutionContext resolutionContext, ResolvingJavaTypeContext resolvingJavaTypeContext,
List<Diagnostic> diagnostics) {
Expand Down Expand Up @@ -391,7 +415,7 @@ private ResolvedJavaTypeInfo validateExpressionParts(Parts parts, Section ownerS
ResolvedJavaTypeInfo resolvedJavaType = null;
String namespace = null;
for (int i = 0; i < parts.getChildCount(); i++) {
Part current = ((Part) parts.getChild(i));
Part current = (parts.getChild(i));

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

/**
* Validate the given property, method part.
*
*
* @param part the property, method part to validate.
* @param ownerSection the owner section and null otherwise.
* @param template the template.
Expand All @@ -596,7 +620,7 @@ private ResolvedJavaTypeInfo validateObjectPart(ObjectPart objectPart, Section o
* @param iterableOfType the iterable of type.
* @param diagnostics the diagnostic list to fill.
* @param resolvingJavaTypeContext the resolving Java type context.
*
*
* @return the Java type returned by the member part and null otherwise.
*/
private ResolvedJavaTypeInfo validateMemberPart(Part part, Section ownerSection, Template template,
Expand All @@ -617,7 +641,7 @@ private ResolvedJavaTypeInfo validateMemberPart(Part part, Section ownerSection,

/**
* Validate the given property part.
*
*
* @param part the property part to validate.
* @param ownerSection the owner section and null otherwise.
* @param template the template.
Expand All @@ -627,7 +651,7 @@ private ResolvedJavaTypeInfo validateMemberPart(Part part, Section ownerSection,
* @param iterableOfType the iterable of type.
* @param diagnostics the diagnostic list to fill.
* @param resolvingJavaTypeContext the resolving Java type context.
*
*
* @return the Java type returned by the member part and null otherwise.
*/
private ResolvedJavaTypeInfo validatePropertyPart(PropertyPart part, Section ownerSection, Template template,
Expand All @@ -650,7 +674,7 @@ private ResolvedJavaTypeInfo validatePropertyPart(PropertyPart part, Section own

/**
* Validate the given method part.
*
*
* @param part the method part to validate.
* @param ownerSection the owner section and null otherwise.
* @param template the template.
Expand All @@ -660,7 +684,7 @@ private ResolvedJavaTypeInfo validatePropertyPart(PropertyPart part, Section own
* @param iterableOfType the iterable of type.
* @param diagnostics the diagnostic list to fill.
* @param resolvingJavaTypeContext the resolving Java type context.
*
*
* @return the Java type returned by the member part and null otherwise.
*/
private ResolvedJavaTypeInfo validateMethodPart(MethodPart methodPart, Section ownerSection, Template template,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
import static com.redhat.qute.services.diagnostics.QuteDiagnosticContants.DIAGNOSTIC_DATA_TAG;
import static com.redhat.qute.services.diagnostics.QuteDiagnosticContants.QUTE_SOURCE;

import java.util.List;

import org.eclipse.lsp4j.Diagnostic;
import org.eclipse.lsp4j.DiagnosticSeverity;
import org.eclipse.lsp4j.DiagnosticTag;
import org.eclipse.lsp4j.Range;

import com.google.gson.JsonObject;
Expand Down Expand Up @@ -55,4 +58,13 @@ public static Diagnostic createDiagnostic(Range range, String message, Diagnosti
errorCode != null ? errorCode.getCode() : null);
return diagnostic;
}

public static Diagnostic createDiagnosticWithTags(Range range, DiagnosticSeverity severity,
IQuteErrorCode errorCode, List<DiagnosticTag> tags, Object... arguments) {
String message = errorCode.getMessage(arguments);
Diagnostic diagnostic = new Diagnostic(range, message, severity, QUTE_SOURCE,
errorCode != null ? errorCode.getCode() : null);
diagnostic.setTags(tags);
return diagnostic;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ public enum QuteErrorCode implements IQuteErrorCode {

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

SyntaxError("Syntax error: `{0}`.");
SyntaxError("Syntax error: `{0}`."),

// Error code for deprecated #with section
DeprecatedWithSection("`with` is deprecated. Use `let` instead.");

private final String rawMessage;

Expand Down

0 comments on commit 00f52fa

Please sign in to comment.