Search in sources :

Example 6 with BadLocationException

use of com.redhat.qute.ls.commons.BadLocationException 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 7 with BadLocationException

use of com.redhat.qute.ls.commons.BadLocationException 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 8 with BadLocationException

use of com.redhat.qute.ls.commons.BadLocationException 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)

Example 9 with BadLocationException

use of com.redhat.qute.ls.commons.BadLocationException in project quarkus-ls by redhat-developer.

the class QuteProject method collectInsert.

private void collectInsert(String insertParamater, Node parent, Template template, List<QuteIndex> indexes) {
    if (parent.getKind() == NodeKind.Section) {
        Section section = (Section) parent;
        if (section.getSectionKind() == SectionKind.INSERT) {
            Parameter parameter = section.getParameterAtIndex(0);
            if (parameter != null) {
                try {
                    if (insertParamater == null || insertParamater.equals(parameter.getValue())) {
                        Position position = template.positionAt(parameter.getStart());
                        Path path = createPath(template.getUri());
                        QuteTemplateIndex templateIndex = new QuteTemplateIndex(path, template.getTemplateId());
                        QuteIndex index = new QuteIndex("insert", parameter.getValue(), position, SectionKind.INSERT, templateIndex);
                        indexes.add(index);
                    }
                } catch (BadLocationException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    List<Node> children = parent.getChildren();
    for (Node node : children) {
        collectInsert(insertParamater, node, template, indexes);
    }
}
Also used : Path(java.nio.file.Path) FileUtils.createPath(com.redhat.qute.utils.FileUtils.createPath) QuteTemplateIndex(com.redhat.qute.project.indexing.QuteTemplateIndex) Position(org.eclipse.lsp4j.Position) Node(com.redhat.qute.parser.template.Node) QuteIndex(com.redhat.qute.project.indexing.QuteIndex) Parameter(com.redhat.qute.parser.template.Parameter) DataModelParameter(com.redhat.qute.commons.datamodel.DataModelParameter) Section(com.redhat.qute.parser.template.Section) BadLocationException(com.redhat.qute.ls.commons.BadLocationException)

Example 10 with BadLocationException

use of com.redhat.qute.ls.commons.BadLocationException in project quarkus-ls by redhat-developer.

the class QuteCodeActions method doCodeActionsForUndefinedSectionTag.

private static void doCodeActionsForUndefinedSectionTag(Template template, Diagnostic diagnostic, List<CodeAction> codeActions) {
    QuteProject project = template.getProject();
    if (project == null) {
        return;
    }
    try {
        String tagName = null;
        JsonObject data = (JsonObject) diagnostic.getData();
        if (data != null) {
            tagName = data.get(DIAGNOSTIC_DATA_TAG).getAsString();
        } else {
            int offset = template.offsetAt(diagnostic.getRange().getStart());
            Node node = template.findNodeAt(offset);
            node = QutePositionUtility.findBestNode(offset, node);
            if (node.getKind() == NodeKind.Section) {
                Section section = (Section) node;
                tagName = section.getTag();
            }
        }
        if (tagName == null) {
            return;
        }
        // TODO : use a settings to know the preferred file extension
        String preferedFileExtension = ".html";
        String tagFileUri = project.getTagsDir().resolve(tagName + preferedFileExtension).toUri().toString();
        String title = MessageFormat.format(UNDEFINED_SECTION_TAG_CODEACTION_TITLE, tagName);
        CodeAction createUserTagFile = CodeActionFactory.createFile(title, tagFileUri, "", diagnostic);
        codeActions.add(createUserTagFile);
    } catch (BadLocationException e) {
        LOGGER.log(Level.SEVERE, "Creation of undefined user tag code action failed", e);
    }
}
Also used : Node(com.redhat.qute.parser.template.Node) CodeAction(org.eclipse.lsp4j.CodeAction) JsonObject(com.google.gson.JsonObject) QuteProject(com.redhat.qute.project.QuteProject) Section(com.redhat.qute.parser.template.Section) BadLocationException(com.redhat.qute.ls.commons.BadLocationException)

Aggregations

BadLocationException (com.redhat.qute.ls.commons.BadLocationException)10 Node (com.redhat.qute.parser.template.Node)10 Part (com.redhat.qute.parser.expression.Part)4 Section (com.redhat.qute.parser.template.Section)4 ObjectPart (com.redhat.qute.parser.expression.ObjectPart)3 ArrayList (java.util.ArrayList)3 Range (org.eclipse.lsp4j.Range)3 JsonObject (com.google.gson.JsonObject)2 NamespacePart (com.redhat.qute.parser.expression.NamespacePart)2 Expression (com.redhat.qute.parser.template.Expression)2 Parameter (com.redhat.qute.parser.template.Parameter)2 Template (com.redhat.qute.parser.template.Template)2 CodeAction (org.eclipse.lsp4j.CodeAction)2 Position (org.eclipse.lsp4j.Position)2 DataModelParameter (com.redhat.qute.commons.datamodel.DataModelParameter)1 TextDocument (com.redhat.qute.ls.commons.TextDocument)1 MethodPart (com.redhat.qute.parser.expression.MethodPart)1 Parts (com.redhat.qute.parser.expression.Parts)1 PropertyPart (com.redhat.qute.parser.expression.PropertyPart)1 ParameterDeclaration (com.redhat.qute.parser.template.ParameterDeclaration)1