Search in sources :

Example 16 with Section

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

use of com.redhat.qute.parser.template.Section 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)

Example 18 with Section

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

the class Part method getParentSection.

@Override
public Section getParentSection() {
    Parts parts = getParent();
    Expression expression = parts.getParent();
    Node parent = expression.getParent();
    if (parent.getKind() == NodeKind.Parameter) {
        // Its' a parameter which belongs to a section (ex : items):
        // {#for item in items}
        // In this case we must get the parent of the parameter section
        Node ownerSection = parent.getParent();
        parent = ownerSection.getParent();
    }
    // loop for parent node to retrieve the parent section.
    while (parent != null) {
        if (parent.getKind() == NodeKind.Section) {
            return (Section) parent;
        }
        parent = parent.getParent();
    }
    return null;
}
Also used : Expression(com.redhat.qute.parser.template.Expression) Node(com.redhat.qute.parser.template.Node) 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