Search in sources :

Example 1 with ParameterDeclaration

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

the class QuteDefinition method findDefinitionFromPartWithNamespace.

private CompletableFuture<List<? extends LocationLink>> findDefinitionFromPartWithNamespace(String namespace, Part part, Template template) {
    String projectUri = template.getProjectUri();
    if (NamespacePart.DATA_NAMESPACE.equals(namespace)) {
        // {data:it|em}
        // check if it is defined in parameter declaration
        ParameterDeclaration parameterDeclaration = template.findInParameterDeclarationByAlias(part.getPartName());
        if (parameterDeclaration != null) {
            String targetUri = template.getUri();
            Range targetRange = QutePositionUtility.selectAlias(parameterDeclaration);
            Range originSelectionRange = QutePositionUtility.createRange(part);
            LocationLink locationLink = new LocationLink(targetUri, targetRange, targetRange, originSelectionRange);
            return CompletableFuture.completedFuture(Arrays.asList(locationLink));
        }
        // check if it is defined with @CheckedTemplate
        if (projectUri != null) {
            return findDefinitionFromParameterDataModel(part, template, projectUri);
        }
        return NO_DEFINITION;
    }
    if (projectUri != null) {
        // {config:booleanP|roperty(propertyName)}
        return // 
        javaCache.findJavaElementWithNamespace(namespace, part.getPartName(), projectUri).thenCompose(member -> {
            return findDefinitionFromJavaMember(member, part, projectUri);
        });
    }
    return NO_DEFINITION;
}
Also used : LocationLink(org.eclipse.lsp4j.LocationLink) Range(org.eclipse.lsp4j.Range) ParameterDeclaration(com.redhat.qute.parser.template.ParameterDeclaration)

Example 2 with ParameterDeclaration

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

the class QuteDiagnostics method validateDataModel.

private void validateDataModel(Node parent, Template template, QuteValidationSettings validationSettings, ResolvingJavaTypeContext resolvingJavaTypeContext, ResolutionContext currentContext, List<Diagnostic> diagnostics) {
    ResolutionContext previousContext = currentContext;
    List<Node> children = parent.getChildren();
    for (Node node : children) {
        switch(node.getKind()) {
            case ParameterDeclaration:
                {
                    ParameterDeclaration parameter = (ParameterDeclaration) node;
                    String javaTypeToResolve = parameter.getJavaType();
                    if (!StringUtils.isEmpty(javaTypeToResolve)) {
                        String projectUri = template.getProjectUri();
                        if (projectUri != null) {
                            List<JavaTypeRangeOffset> classNameRanges = parameter.getJavaTypeNameRanges();
                            for (RangeOffset classNameRange : classNameRanges) {
                                String className = template.getText(classNameRange);
                                ResolvedJavaTypeInfo resolvedJavaType = resolveJavaType(className, projectUri, resolvingJavaTypeContext);
                                if (resolvedJavaType == null) {
                                    // Java type doesn't exist
                                    Range range = QutePositionUtility.createRange(classNameRange, template);
                                    Diagnostic diagnostic = createDiagnostic(range, DiagnosticSeverity.Error, QuteErrorCode.UnknownType, className);
                                    diagnostics.add(diagnostic);
                                } else if (!isResolvingJavaType(resolvedJavaType)) {
                                    currentContext.put(javaTypeToResolve, resolvedJavaType);
                                }
                            }
                        }
                    }
                    break;
                }
            case Section:
                {
                    Section section = (Section) node;
                    if (canChangeContext(section)) {
                        currentContext = new ResolutionContext(currentContext);
                    }
                    List<Parameter> parameters = section.getParameters();
                    // validate expression parameters
                    for (Parameter parameter : parameters) {
                        Expression expression = parameter.getJavaTypeExpression();
                        if (expression != null) {
                            ResolvedJavaTypeInfo result = validateExpression(expression, section, template, validationSettings, previousContext, resolvingJavaTypeContext, diagnostics);
                            switch(section.getSectionKind()) {
                                case FOR:
                                case EACH:
                                    String alias = ((LoopSection) section).getAlias();
                                    currentContext.put(alias, result);
                                    break;
                                case WITH:
                                    currentContext.setWithObject(result);
                                    break;
                                case LET:
                                case SET:
                                    currentContext.put(parameter.getName(), result);
                                    break;
                                default:
                            }
                        }
                    }
                    switch(section.getSectionKind()) {
                        case INCLUDE:
                            validateIncludeSection((IncludeSection) section, diagnostics);
                            break;
                        default:
                            validateSectionTag(section, template, resolvingJavaTypeContext, diagnostics);
                    }
                    break;
                }
            case Expression:
                {
                    validateExpression((Expression) node, null, template, validationSettings, previousContext, resolvingJavaTypeContext, diagnostics);
                    break;
                }
            default:
        }
        validateDataModel(node, template, validationSettings, resolvingJavaTypeContext, currentContext, diagnostics);
    }
}
Also used : Node(com.redhat.qute.parser.template.Node) ResolvedJavaTypeInfo(com.redhat.qute.commons.ResolvedJavaTypeInfo) DiagnosticDataFactory.createDiagnostic(com.redhat.qute.services.diagnostics.DiagnosticDataFactory.createDiagnostic) Diagnostic(org.eclipse.lsp4j.Diagnostic) Range(org.eclipse.lsp4j.Range) IncludeSection(com.redhat.qute.parser.template.sections.IncludeSection) LoopSection(com.redhat.qute.parser.template.sections.LoopSection) Section(com.redhat.qute.parser.template.Section) Expression(com.redhat.qute.parser.template.Expression) JavaTypeRangeOffset(com.redhat.qute.parser.template.ParameterDeclaration.JavaTypeRangeOffset) RangeOffset(com.redhat.qute.parser.template.RangeOffset) Parameter(com.redhat.qute.parser.template.Parameter) IncludeSection(com.redhat.qute.parser.template.sections.IncludeSection) List(java.util.List) ArrayList(java.util.ArrayList) ParameterDeclaration(com.redhat.qute.parser.template.ParameterDeclaration)

Example 3 with ParameterDeclaration

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

the class QuteHover method doHoverForExpressionPartWithNamespace.

public CompletableFuture<Hover> doHoverForExpressionPartWithNamespace(String namespace, Part part, Template template, String projectUri, HoverRequest hoverRequest) {
    if (NamespacePart.DATA_NAMESPACE.equals(namespace)) {
        // {data:it|em}
        // check if it is defined in parameter declaration
        ParameterDeclaration parameterDeclaration = template.findInParameterDeclarationByAlias(part.getPartName());
        if (parameterDeclaration != null) {
            return doHoverForJavaType(part, parameterDeclaration.getJavaType(), projectUri, hoverRequest);
        }
        // check if it is defined with @CheckedTemplate
        if (projectUri != null) {
            return // 
            template.getParameterDataModel(part.getPartName()).thenCompose(parameter -> {
                if (parameter != null) {
                    return doHoverForJavaType(part, parameter.getJavaType(), projectUri, hoverRequest);
                }
                return NO_HOVER;
            });
        }
        return NO_HOVER;
    }
    if (projectUri != null) {
        // {inject:be|an}
        return // 
        javaCache.findJavaElementWithNamespace(namespace, part.getPartName(), projectUri).thenApply(javaElement -> {
            if (javaElement == null) {
                return null;
            }
            if (javaElement instanceof JavaTypeInfo) {
                return doHoverForJavaType(part, (JavaTypeInfo) javaElement, hoverRequest);
            }
            JavaMemberInfo member = (JavaMemberInfo) javaElement;
            boolean hasMarkdown = hoverRequest.canSupportMarkupKind(MarkupKind.MARKDOWN);
            MarkupContent content = DocumentationUtils.getDocumentation(member, null, hasMarkdown);
            Range range = QutePositionUtility.createRange(part);
            return new Hover(content, range);
        });
    }
    return NO_HOVER;
}
Also used : JavaMemberInfo(com.redhat.qute.commons.JavaMemberInfo) JavaTypeInfo(com.redhat.qute.commons.JavaTypeInfo) ResolvedJavaTypeInfo(com.redhat.qute.commons.ResolvedJavaTypeInfo) Hover(org.eclipse.lsp4j.Hover) Range(org.eclipse.lsp4j.Range) MarkupContent(org.eclipse.lsp4j.MarkupContent) ParameterDeclaration(com.redhat.qute.parser.template.ParameterDeclaration)

Example 4 with ParameterDeclaration

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

the class QuteCompletionsForExpression method doCompleteExpressionForObjectPartWithParameterAlias.

private void doCompleteExpressionForObjectPartWithParameterAlias(Template template, Range range, CompletionList list) {
    List<String> aliases = // 
    template.getChildren().stream().filter(// 
    n -> n.getKind() == NodeKind.ParameterDeclaration).map(// 
    n -> ((ParameterDeclaration) n).getAlias()).filter(// 
    alias -> alias != null).collect(Collectors.toList());
    for (String alias : aliases) {
        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);
    }
}
Also used : Template(com.redhat.qute.parser.template.Template) MethodValueResolver(com.redhat.qute.project.datamodel.resolvers.MethodValueResolver) JavaFieldInfo(com.redhat.qute.commons.JavaFieldInfo) StringUtils(com.redhat.qute.utils.StringUtils) SectionMetadata(com.redhat.qute.parser.template.SectionMetadata) MethodPart(com.redhat.qute.parser.expression.MethodPart) QuteCompletionSettings(com.redhat.qute.settings.QuteCompletionSettings) NodeKind(com.redhat.qute.parser.template.NodeKind) Parameter(com.redhat.qute.parser.template.Parameter) Expression(com.redhat.qute.parser.template.Expression) WithSection(com.redhat.qute.parser.template.sections.WithSection) Either(org.eclipse.lsp4j.jsonrpc.messages.Either) Parts(com.redhat.qute.parser.expression.Parts) SnippetsBuilder(com.redhat.qute.ls.commons.SnippetsBuilder) MATCH_NAME_ANY(com.redhat.qute.project.datamodel.resolvers.ValueResolver.MATCH_NAME_ANY) InsertTextFormat(org.eclipse.lsp4j.InsertTextFormat) ExtendedDataModelTemplate(com.redhat.qute.project.datamodel.ExtendedDataModelTemplate) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) QuteFormattingSettings(com.redhat.qute.settings.QuteFormattingSettings) CompletionItem(org.eclipse.lsp4j.CompletionItem) List(java.util.List) Part(com.redhat.qute.parser.expression.Part) ResolvedJavaTypeInfo(com.redhat.qute.commons.ResolvedJavaTypeInfo) FieldValueResolver(com.redhat.qute.project.datamodel.resolvers.FieldValueResolver) ExtendedDataModelParameter(com.redhat.qute.project.datamodel.ExtendedDataModelParameter) LoopSection(com.redhat.qute.parser.template.sections.LoopSection) ValueResolver(com.redhat.qute.project.datamodel.resolvers.ValueResolver) UserTagUtils(com.redhat.qute.utils.UserTagUtils) QutePositionUtility(com.redhat.qute.utils.QutePositionUtility) CompletableFuture(java.util.concurrent.CompletableFuture) Range(org.eclipse.lsp4j.Range) ArrayList(java.util.ArrayList) JavaDataModelCache(com.redhat.qute.project.datamodel.JavaDataModelCache) HashSet(java.util.HashSet) SectionKind(com.redhat.qute.parser.template.SectionKind) TextEdit(org.eclipse.lsp4j.TextEdit) CompletionItemKind(org.eclipse.lsp4j.CompletionItemKind) Section(com.redhat.qute.parser.template.Section) CompletionList(org.eclipse.lsp4j.CompletionList) NamespacePart(com.redhat.qute.parser.expression.NamespacePart) Node(com.redhat.qute.parser.template.Node) JavaParameterInfo(com.redhat.qute.commons.JavaParameterInfo) CancelChecker(org.eclipse.lsp4j.jsonrpc.CancelChecker) ParameterDeclaration(com.redhat.qute.parser.template.ParameterDeclaration) EMPTY_FUTURE_COMPLETION(com.redhat.qute.services.QuteCompletions.EMPTY_FUTURE_COMPLETION) JavaMethodInfo(com.redhat.qute.commons.JavaMethodInfo) EMPTY_COMPLETION(com.redhat.qute.services.QuteCompletions.EMPTY_COMPLETION) CompletionItem(org.eclipse.lsp4j.CompletionItem) TextEdit(org.eclipse.lsp4j.TextEdit)

Example 5 with ParameterDeclaration

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

the class QuteSearchUtils method searchDeclaredObjectInParameterDeclaration.

private static void searchDeclaredObjectInParameterDeclaration(ObjectPart part, BiConsumer<Node, Range> collector) {
    String partName = part.getPartName();
    ParameterDeclaration parameterDeclaration = part.getOwnerTemplate().findInParameterDeclarationByAlias(partName);
    if (parameterDeclaration != null) {
        Range targetRange = QutePositionUtility.selectAlias(parameterDeclaration);
        collector.accept(parameterDeclaration, targetRange);
    }
}
Also used : Range(org.eclipse.lsp4j.Range) ParameterDeclaration(com.redhat.qute.parser.template.ParameterDeclaration)

Aggregations

ParameterDeclaration (com.redhat.qute.parser.template.ParameterDeclaration)7 Range (org.eclipse.lsp4j.Range)6 Parameter (com.redhat.qute.parser.template.Parameter)4 ResolvedJavaTypeInfo (com.redhat.qute.commons.ResolvedJavaTypeInfo)3 Node (com.redhat.qute.parser.template.Node)3 Section (com.redhat.qute.parser.template.Section)3 LoopSection (com.redhat.qute.parser.template.sections.LoopSection)3 NamespacePart (com.redhat.qute.parser.expression.NamespacePart)2 Part (com.redhat.qute.parser.expression.Part)2 Expression (com.redhat.qute.parser.template.Expression)2 RangeOffset (com.redhat.qute.parser.template.RangeOffset)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 JavaFieldInfo (com.redhat.qute.commons.JavaFieldInfo)1 JavaMemberInfo (com.redhat.qute.commons.JavaMemberInfo)1 JavaMethodInfo (com.redhat.qute.commons.JavaMethodInfo)1 JavaParameterInfo (com.redhat.qute.commons.JavaParameterInfo)1 JavaTypeInfo (com.redhat.qute.commons.JavaTypeInfo)1 BadLocationException (com.redhat.qute.ls.commons.BadLocationException)1 SnippetsBuilder (com.redhat.qute.ls.commons.SnippetsBuilder)1