Search in sources :

Example 11 with Parameter

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

the class SwitchSection method accept0.

@Override
protected void accept0(ASTVisitor visitor) {
    boolean visitChildren = visitor.visit(this);
    if (visitChildren) {
        List<Parameter> parameters = getParameters();
        for (Parameter parameter : parameters) {
            acceptChild(visitor, parameter);
        }
        acceptChildren(visitor, getChildren());
    }
    visitor.endVisit(this);
}
Also used : Parameter(com.redhat.qute.parser.template.Parameter)

Example 12 with Parameter

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

the class EachSection method accept0.

@Override
protected void accept0(ASTVisitor visitor) {
    boolean visitChildren = visitor.visit(this);
    if (visitChildren) {
        List<Parameter> parameters = getParameters();
        for (Parameter parameter : parameters) {
            acceptChild(visitor, parameter);
        }
        acceptChildren(visitor, getChildren());
    }
    visitor.endVisit(this);
}
Also used : Parameter(com.redhat.qute.parser.template.Parameter)

Example 13 with Parameter

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

the class ElseSection method accept0.

@Override
protected void accept0(ASTVisitor visitor) {
    boolean visitChildren = visitor.visit(this);
    if (visitChildren) {
        List<Parameter> parameters = getParameters();
        for (Parameter parameter : parameters) {
            acceptChild(visitor, parameter);
        }
        acceptChildren(visitor, getChildren());
    }
    visitor.endVisit(this);
}
Also used : Parameter(com.redhat.qute.parser.template.Parameter)

Example 14 with Parameter

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

the class QuteCompletionsForExpression method doCompleteExpressionForObjectPartWithParentNodes.

private void doCompleteExpressionForObjectPartWithParentNodes(Node part, Node node, Range range, int offset, String projectUri, Set<String> existingVars, QuteCompletionSettings completionSettings, QuteFormattingSettings formattingSettings, CompletionList list) {
    Section section = node != null ? node.getParentSection() : null;
    if (section == null) {
        return;
    }
    if (section.getKind() == NodeKind.Section) {
        boolean collect = true;
        if (section.getSectionKind() == SectionKind.FOR || section.getSectionKind() == SectionKind.EACH) {
            LoopSection iterableSection = ((LoopSection) section);
            if (iterableSection.isInElseBlock(offset)) {
                // Completion is triggered after a #else inside a #for, we don't provide
                // completion for metadata or aliases
                collect = false;
            }
        }
        if (collect) {
            // 1) Completion for metadata section
            List<SectionMetadata> metadatas = section.getMetadata();
            for (SectionMetadata metadata : metadatas) {
                String name = metadata.getName();
                if (!existingVars.contains(name)) {
                    existingVars.add(name);
                    CompletionItem item = new CompletionItem();
                    item.setLabel(name);
                    item.setKind(CompletionItemKind.Keyword);
                    // Display metadata section (ex : count for #each) after declared objects
                    item.setSortText("Za" + name);
                    TextEdit textEdit = new TextEdit(range, name);
                    item.setTextEdit(Either.forLeft(textEdit));
                    item.setDetail(metadata.getDescription());
                    list.getItems().add(item);
                }
            }
            // 2) Completion for aliases section
            switch(section.getSectionKind()) {
                case EACH:
                case FOR:
                    LoopSection iterableSection = ((LoopSection) section);
                    // Completion for iterable section like #each, #for
                    String alias = iterableSection.getAlias();
                    if (!StringUtils.isEmpty(alias)) {
                        if (!existingVars.contains(alias)) {
                            existingVars.add(alias);
                            CompletionItem item = new CompletionItem();
                            item.setLabel(alias);
                            item.setKind(CompletionItemKind.Reference);
                            TextEdit textEdit = new TextEdit(range, alias);
                            item.setTextEdit(Either.forLeft(textEdit));
                            list.getItems().add(item);
                        }
                    }
                    break;
                case LET:
                case SET:
                    // completion for parameters coming from #let, #set
                    List<Parameter> parameters = section.getParameters();
                    if (parameters != null) {
                        for (Parameter parameter : parameters) {
                            String parameterName = parameter.getName();
                            if (!existingVars.contains(parameterName)) {
                                existingVars.add(parameterName);
                                CompletionItem item = new CompletionItem();
                                item.setLabel(parameterName);
                                item.setKind(CompletionItemKind.Reference);
                                TextEdit textEdit = new TextEdit(range, parameterName);
                                item.setTextEdit(Either.forLeft(textEdit));
                                list.getItems().add(item);
                            }
                        }
                    }
                    break;
                case WITH:
                    // Completion for properties/methods of with object from #with
                    Parameter object = ((WithSection) section).getObjectParameter();
                    if (object != null) {
                        ResolvedJavaTypeInfo withJavaTypeInfo = javaCache.resolveJavaType(object, projectUri).getNow(null);
                        if (withJavaTypeInfo != null) {
                            fillCompletionFields(withJavaTypeInfo, range, projectUri, existingVars, list);
                            fillCompletionMethods(withJavaTypeInfo, range, projectUri, completionSettings, formattingSettings, existingVars, new HashSet<>(), list);
                        }
                    }
                    break;
                default:
            }
        }
    }
    doCompleteExpressionForObjectPartWithParentNodes(part, section, range, offset, projectUri, existingVars, completionSettings, formattingSettings, list);
}
Also used : WithSection(com.redhat.qute.parser.template.sections.WithSection) ResolvedJavaTypeInfo(com.redhat.qute.commons.ResolvedJavaTypeInfo) WithSection(com.redhat.qute.parser.template.sections.WithSection) LoopSection(com.redhat.qute.parser.template.sections.LoopSection) Section(com.redhat.qute.parser.template.Section) LoopSection(com.redhat.qute.parser.template.sections.LoopSection) CompletionItem(org.eclipse.lsp4j.CompletionItem) TextEdit(org.eclipse.lsp4j.TextEdit) SectionMetadata(com.redhat.qute.parser.template.SectionMetadata) Parameter(com.redhat.qute.parser.template.Parameter) ExtendedDataModelParameter(com.redhat.qute.project.datamodel.ExtendedDataModelParameter)

Example 15 with Parameter

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

the class QutePositionUtility method findBestNode.

/**
 * Find the best node from the given expression at the given offset.
 *
 * @param expression the expression node.
 * @param offset     the offset.
 *
 * @return the best node from the given expression at the given offset.
 */
private static Node findBestNode(Expression expression, int offset) {
    Node expressionNode = expression.findNodeExpressionAt(offset);
    if (expressionNode != null) {
        if (expressionNode instanceof MethodPart) {
            MethodPart method = (MethodPart) expressionNode;
            Parameter parameter = method.getParameterAtOffset(offset);
            if (parameter != null) {
                Expression parameterExpression = parameter.getJavaTypeExpression();
                if (parameterExpression != null) {
                    return findBestNode(parameterExpression, offset);
                }
                return parameter;
            }
        }
        return expressionNode;
    }
    return expression;
}
Also used : Expression(com.redhat.qute.parser.template.Expression) Node(com.redhat.qute.parser.template.Node) Parameter(com.redhat.qute.parser.template.Parameter) MethodPart(com.redhat.qute.parser.expression.MethodPart)

Aggregations

Parameter (com.redhat.qute.parser.template.Parameter)30 Node (com.redhat.qute.parser.template.Node)9 Section (com.redhat.qute.parser.template.Section)9 Range (org.eclipse.lsp4j.Range)9 Expression (com.redhat.qute.parser.template.Expression)6 LoopSection (com.redhat.qute.parser.template.sections.LoopSection)6 ResolvedJavaTypeInfo (com.redhat.qute.commons.ResolvedJavaTypeInfo)3 NamespacePart (com.redhat.qute.parser.expression.NamespacePart)3 Part (com.redhat.qute.parser.expression.Part)3 ParameterDeclaration (com.redhat.qute.parser.template.ParameterDeclaration)3 DiagnosticDataFactory.createDiagnostic (com.redhat.qute.services.diagnostics.DiagnosticDataFactory.createDiagnostic)3 Path (java.nio.file.Path)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Diagnostic (org.eclipse.lsp4j.Diagnostic)3 BadLocationException (com.redhat.qute.ls.commons.BadLocationException)2 MethodPart (com.redhat.qute.parser.expression.MethodPart)2 RangeOffset (com.redhat.qute.parser.template.RangeOffset)2 Template (com.redhat.qute.parser.template.Template)2 IncludeSection (com.redhat.qute.parser.template.sections.IncludeSection)2