Search in sources :

Example 16 with Node

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

the class QuteHighlighting method findDocumentHighlights.

public List<DocumentHighlight> findDocumentHighlights(Template template, Position position, CancelChecker cancelChecker) {
    try {
        List<DocumentHighlight> highlights = new ArrayList<>();
        int offset = template.offsetAt(position);
        Node node = template.findNodeAt(offset);
        if (node == null) {
            return Collections.emptyList();
        }
        node = QutePositionUtility.findBestNode(offset, node);
        switch(node.getKind()) {
            case ParameterDeclaration:
            case Parameter:
                highlightReferenceObjectPart(node, offset, highlights, cancelChecker);
                break;
            case ExpressionPart:
                Part part = (Part) node;
                if (part.getPartKind() == PartKind.Object) {
                    highlightDeclaredObject((ObjectPart) part, highlights, cancelChecker);
                }
                break;
            case Section:
                higlightSection((Section) node, offset, position, highlights, cancelChecker);
                break;
            default:
        }
        return highlights;
    } catch (BadLocationException e) {
        LOGGER.log(Level.SEVERE, "In QuteHighlighting the client provided Position is at a BadLocation", e);
        return Collections.emptyList();
    }
}
Also used : DocumentHighlight(org.eclipse.lsp4j.DocumentHighlight) ObjectPart(com.redhat.qute.parser.expression.ObjectPart) Part(com.redhat.qute.parser.expression.Part) Node(com.redhat.qute.parser.template.Node) ArrayList(java.util.ArrayList) BadLocationException(com.redhat.qute.ls.commons.BadLocationException)

Example 17 with Node

use of com.redhat.qute.parser.template.Node 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 18 with Node

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

the class QuteSearchUtils method searchReferencedObjects.

private static void searchReferencedObjects(String partName, PartNameMatcher matcher, Node owerNode, BiConsumer<Node, Range> collector, CancelChecker cancelChecker) {
    Template template = owerNode.getOwnerTemplate();
    Node parent = owerNode.getKind() == NodeKind.ParameterDeclaration ? template : owerNode;
    searchReferencedObjects(partName, matcher, parent, owerNode, collector, cancelChecker);
}
Also used : Node(com.redhat.qute.parser.template.Node) Template(com.redhat.qute.parser.template.Template)

Example 19 with Node

use of com.redhat.qute.parser.template.Node 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 20 with Node

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

the class QuteLinkedEditing method findLinkedEditingRanges.

public LinkedEditingRanges findLinkedEditingRanges(Template template, Position position, CancelChecker cancelChecker) {
    try {
        int offset = template.offsetAt(position);
        Node node = template.findNodeAt(offset);
        if (node == null) {
            return null;
        }
        node = QutePositionUtility.findBestNode(offset, node);
        List<Range> ranges = new ArrayList<>();
        // 
        QuteSearchUtils.searchReferencedObjects(// 
        node, // 
        offset, (n, range) -> ranges.add(range), true, cancelChecker);
        if (ranges.size() <= 1) {
            return null;
        }
        return new LinkedEditingRanges(ranges);
    } catch (BadLocationException e) {
        LOGGER.log(Level.SEVERE, "In QuteLinkedEditing the client provided Position is at a BadLocation", e);
        return null;
    }
}
Also used : Node(com.redhat.qute.parser.template.Node) ArrayList(java.util.ArrayList) Range(org.eclipse.lsp4j.Range) BadLocationException(com.redhat.qute.ls.commons.BadLocationException) LinkedEditingRanges(org.eclipse.lsp4j.LinkedEditingRanges)

Aggregations

Node (com.redhat.qute.parser.template.Node)27 Section (com.redhat.qute.parser.template.Section)14 BadLocationException (com.redhat.qute.ls.commons.BadLocationException)10 Parameter (com.redhat.qute.parser.template.Parameter)10 Range (org.eclipse.lsp4j.Range)10 Expression (com.redhat.qute.parser.template.Expression)8 ArrayList (java.util.ArrayList)7 Part (com.redhat.qute.parser.expression.Part)6 ObjectPart (com.redhat.qute.parser.expression.ObjectPart)5 Template (com.redhat.qute.parser.template.Template)5 Parts (com.redhat.qute.parser.expression.Parts)4 IncludeSection (com.redhat.qute.parser.template.sections.IncludeSection)4 LoopSection (com.redhat.qute.parser.template.sections.LoopSection)4 List (java.util.List)4 ResolvedJavaTypeInfo (com.redhat.qute.commons.ResolvedJavaTypeInfo)3 MethodPart (com.redhat.qute.parser.expression.MethodPart)3 NamespacePart (com.redhat.qute.parser.expression.NamespacePart)3 QuteProject (com.redhat.qute.project.QuteProject)3 QuteIndex (com.redhat.qute.project.indexing.QuteIndex)3 JsonObject (com.google.gson.JsonObject)2