Search in sources :

Example 11 with Section

use of com.redhat.qute.parser.template.Section in project quarkus-ls by redhat-developer.

the class QuteHighlighting method higlightSection.

private static void higlightSection(Section section, int offset, Position position, List<DocumentHighlight> highlights, CancelChecker cancelChecker) throws BadLocationException {
    if (section.isInStartTagName(offset) || section.isInEndTagName(offset)) {
        highlightSectionTag(section, highlights);
        if (!section.getBlockLabels().isEmpty()) {
            // The section can have nested block (ex #for can have #else)
            for (Node node : section.getChildren()) {
                if (node.getKind() == NodeKind.Section && section.getBlockLabels().contains(((Section) node).getSectionKind())) {
                    Section nestedBlock = (Section) node;
                    highlightSectionTag(nestedBlock, highlights);
                }
            }
        } else {
            // Get parent section
            Section parentSection = section.getParentSection();
            if (parentSection != null && parentSection.getBlockLabels().contains(section.getSectionKind())) {
                highlightSectionTag(parentSection, highlights);
            }
        }
    } else {
        highlightReferenceObjectPart(section, offset, highlights, cancelChecker);
    }
}
Also used : Node(com.redhat.qute.parser.template.Node) Section(com.redhat.qute.parser.template.Section)

Example 12 with Section

use of com.redhat.qute.parser.template.Section in project quarkus-ls by redhat-developer.

the class QuteHover method doHover.

public CompletableFuture<Hover> doHover(Template template, Position position, SharedSettings settings, CancelChecker cancelChecker) {
    cancelChecker.checkCanceled();
    HoverRequest hoverRequest = null;
    try {
        hoverRequest = new HoverRequest(template, position, settings);
    } catch (BadLocationException e) {
        LOGGER.log(Level.SEVERE, "Failed creating HoverRequest", e);
        return NO_HOVER;
    }
    Node node = hoverRequest.getNode();
    if (node == null) {
        return NO_HOVER;
    }
    switch(node.getKind()) {
        case Section:
            // - Start end tag definition
            Section section = (Section) node;
            return doHoverForSection(section, template, hoverRequest, cancelChecker);
        case ParameterDeclaration:
            ParameterDeclaration parameterDeclaration = (ParameterDeclaration) node;
            return doHoverForParameterDeclaration(parameterDeclaration, template, hoverRequest, cancelChecker);
        case ExpressionPart:
            Part part = (Part) node;
            return doHoverForExpressionPart(part, template, hoverRequest, cancelChecker);
        case Parameter:
            Parameter parameter = (Parameter) node;
            return doHoverForParameter(parameter, template, hoverRequest);
        default:
            return NO_HOVER;
    }
}
Also used : HoverRequest(com.redhat.qute.services.hover.HoverRequest) NamespacePart(com.redhat.qute.parser.expression.NamespacePart) Part(com.redhat.qute.parser.expression.Part) Node(com.redhat.qute.parser.template.Node) Parameter(com.redhat.qute.parser.template.Parameter) LoopSection(com.redhat.qute.parser.template.sections.LoopSection) Section(com.redhat.qute.parser.template.Section) BadLocationException(com.redhat.qute.ls.commons.BadLocationException) ParameterDeclaration(com.redhat.qute.parser.template.ParameterDeclaration)

Example 13 with Section

use of com.redhat.qute.parser.template.Section in project quarkus-ls by redhat-developer.

the class UserTagUtils method collectUserTagParameters.

private static void collectUserTagParameters(Node parent, Template template, Set<String> extistingObjectParts, Consumer<ObjectPart> collector, CancelChecker cancelChecker) {
    cancelChecker.checkCanceled();
    if (parent.getKind() == NodeKind.Expression) {
        Expression expression = (Expression) parent;
        collectUserTagParameters(expression, extistingObjectParts, collector, cancelChecker);
        return;
    } else if (parent.getKind() == NodeKind.Section) {
        Section section = (Section) parent;
        List<Parameter> parameters = section.getParameters();
        for (Parameter parameter : parameters) {
            if (parameter.isCanHaveExpression()) {
                Expression expression = parameter.getJavaTypeExpression();
                collectUserTagParameters(expression, extistingObjectParts, collector, cancelChecker);
            }
        }
    }
    List<Node> children = parent.getChildren();
    for (Node node : children) {
        collectUserTagParameters(node, template, extistingObjectParts, collector, cancelChecker);
    }
}
Also used : Expression(com.redhat.qute.parser.template.Expression) Node(com.redhat.qute.parser.template.Node) Parameter(com.redhat.qute.parser.template.Parameter) List(java.util.List) Section(com.redhat.qute.parser.template.Section)

Example 14 with Section

use of com.redhat.qute.parser.template.Section in project quarkus-ls by redhat-developer.

the class QuteSearchUtils method searchDeclaredObjectInParameter.

private static Parameter searchDeclaredObjectInParameter(ObjectPart part, CancelChecker cancelChecker) {
    String partName = part.getPartName();
    Node parent = part.getParentSection();
    while (parent != null) {
        if (parent.getKind() == NodeKind.Section) {
            Section section = (Section) parent;
            switch(section.getSectionKind()) {
                case EACH:
                case FOR:
                    LoopSection iterableSection = (LoopSection) section;
                    if (!iterableSection.isInElseBlock(part.getStart())) {
                        String alias = iterableSection.getAlias();
                        if (partName.equals(alias) || section.isMetadata(partName)) {
                            // - or the metadata of the section (ex : item_count)
                            return iterableSection.getAliasParameter();
                        }
                    }
                    break;
                case LET:
                case SET:
                    List<Parameter> parameters = section.getParameters();
                    for (Parameter parameter : parameters) {
                        if (partName.equals(parameter.getName())) {
                            return parameter;
                        }
                    }
                    break;
                default:
            }
        }
        parent = parent.getParent();
    }
    return null;
}
Also used : LoopSection(com.redhat.qute.parser.template.sections.LoopSection) Node(com.redhat.qute.parser.template.Node) Parameter(com.redhat.qute.parser.template.Parameter) LoopSection(com.redhat.qute.parser.template.sections.LoopSection) BaseWhenSection(com.redhat.qute.parser.template.sections.BaseWhenSection) WithSection(com.redhat.qute.parser.template.sections.WithSection) Section(com.redhat.qute.parser.template.Section)

Example 15 with Section

use of com.redhat.qute.parser.template.Section in project quarkus-ls by redhat-developer.

the class QuteSearchUtils method tryToCollectObjectPartOrParameter.

public static void tryToCollectObjectPartOrParameter(String partName, PartNameMatcher matcher, Expression expression, Node ownerNode, BiConsumer<Node, Range> collector) {
    // object part)
    if (!tryToCollectObjectParts(partName, matcher, expression, collector)) {
        if (ownerNode.getKind() == NodeKind.Section) {
            Section onwerSection = (Section) ownerNode;
            // Check the current expression references a metadata of the section
            ObjectPart objectPart = expression.getObjectPart();
            if (objectPart != null) {
                JavaTypeInfoProvider metadata = onwerSection.getMetadata(objectPart.getPartName());
                if (metadata != null) {
                    // Adjust the object part range with the given part name
                    // Example if expression is like {item_count}
                    // Range should be {|item|_count}
                    Range range = QutePositionUtility.createRange(objectPart.getStart(), objectPart.getStart() + partName.length(), objectPart.getOwnerTemplate());
                    collector.accept(objectPart, range);
                }
            }
        }
    }
}
Also used : JavaTypeInfoProvider(com.redhat.qute.parser.template.JavaTypeInfoProvider) ObjectPart(com.redhat.qute.parser.expression.ObjectPart) Range(org.eclipse.lsp4j.Range) LoopSection(com.redhat.qute.parser.template.sections.LoopSection) BaseWhenSection(com.redhat.qute.parser.template.sections.BaseWhenSection) WithSection(com.redhat.qute.parser.template.sections.WithSection) Section(com.redhat.qute.parser.template.Section)

Aggregations

Section (com.redhat.qute.parser.template.Section)18 Node (com.redhat.qute.parser.template.Node)15 Parameter (com.redhat.qute.parser.template.Parameter)11 LoopSection (com.redhat.qute.parser.template.sections.LoopSection)8 Range (org.eclipse.lsp4j.Range)7 Expression (com.redhat.qute.parser.template.Expression)6 BadLocationException (com.redhat.qute.ls.commons.BadLocationException)5 ResolvedJavaTypeInfo (com.redhat.qute.commons.ResolvedJavaTypeInfo)4 Part (com.redhat.qute.parser.expression.Part)4 IncludeSection (com.redhat.qute.parser.template.sections.IncludeSection)4 QuteProject (com.redhat.qute.project.QuteProject)4 Parts (com.redhat.qute.parser.expression.Parts)3 JavaTypeInfoProvider (com.redhat.qute.parser.template.JavaTypeInfoProvider)3 ParameterDeclaration (com.redhat.qute.parser.template.ParameterDeclaration)3 Template (com.redhat.qute.parser.template.Template)3 WithSection (com.redhat.qute.parser.template.sections.WithSection)3 QuteIndex (com.redhat.qute.project.indexing.QuteIndex)3 List (java.util.List)3 JavaMemberInfo (com.redhat.qute.commons.JavaMemberInfo)2 JavaTypeInfo (com.redhat.qute.commons.JavaTypeInfo)2