Search in sources :

Example 1 with RangeOffset

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

the class QuteDefinition method findDefinitionFromParameterDeclaration.

private CompletableFuture<List<? extends LocationLink>> findDefinitionFromParameterDeclaration(int offset, ParameterDeclaration parameterDeclaration, Template template) {
    String projectUri = template.getProjectUri();
    if (projectUri != null && parameterDeclaration.isInJavaTypeName(offset)) {
        RangeOffset range = parameterDeclaration.getJavaTypeNameRange(offset);
        if (range != null) {
            String className = template.getText(range);
            QuteJavaDefinitionParams params = new QuteJavaDefinitionParams(className, projectUri);
            return findJavaDefinition(params, () -> QutePositionUtility.createRange(range, template));
        }
    }
    return NO_DEFINITION;
}
Also used : QuteJavaDefinitionParams(com.redhat.qute.commons.QuteJavaDefinitionParams) RangeOffset(com.redhat.qute.parser.template.RangeOffset)

Example 2 with RangeOffset

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

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

the class QuteHover method doHoverForParameterDeclaration.

private CompletableFuture<Hover> doHoverForParameterDeclaration(ParameterDeclaration parameterDeclaration, Template template, HoverRequest hoverRequest, CancelChecker cancelChecker) {
    RangeOffset classNameRange = parameterDeclaration.getJavaTypeNameRange(hoverRequest.getOffset());
    if (classNameRange != null) {
        if (classNameRange != null) {
            String className = template.getText(classNameRange);
            return // 
            javaCache.resolveJavaType(className, template.getProjectUri()).thenApply(resolvedType -> {
                if (resolvedType != null) {
                    boolean hasMarkdown = hoverRequest.canSupportMarkupKind(MarkupKind.MARKDOWN);
                    MarkupContent content = DocumentationUtils.getDocumentation(resolvedType, hasMarkdown);
                    Range range = QutePositionUtility.createRange(classNameRange, template);
                    return new Hover(content, range);
                }
                return null;
            });
        }
    }
    return NO_HOVER;
}
Also used : Hover(org.eclipse.lsp4j.Hover) RangeOffset(com.redhat.qute.parser.template.RangeOffset) Range(org.eclipse.lsp4j.Range) MarkupContent(org.eclipse.lsp4j.MarkupContent)

Example 4 with RangeOffset

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

the class QuteSearchUtils method searchReferencedObjects.

// ------------------- Search referenced objects
/**
 * Search referenced object of the given node.
 *
 * @param node          the origin node.
 * @param offset        the offset.
 * @param collector     the collector to collect node and range.
 * @param includeNode   true if the origin node must be collected and false
 *                      otherwise.
 * @param cancelChecker the cancel checker.
 */
public static void searchReferencedObjects(Node node, int offset, BiConsumer<Node, Range> collector, boolean includeNode, CancelChecker cancelChecker) {
    switch(node.getKind()) {
        case ParameterDeclaration:
            {
                ParameterDeclaration parameterDeclaration = (ParameterDeclaration) node;
                if (parameterDeclaration.isInJavaTypeName(offset)) {
                    // {@org.acme.It|em item}
                    RangeOffset rangeOffset = parameterDeclaration.getJavaTypeNameRange(offset);
                    if (rangeOffset != null) {
                        Range range = QutePositionUtility.createRange(rangeOffset, node.getOwnerTemplate());
                        collector.accept(parameterDeclaration, range);
                    }
                } else if (parameterDeclaration.isInAlias(offset)) {
                    // {@org.acme.Item it|em}
                    String alias = parameterDeclaration.getAlias();
                    if (includeNode) {
                        Range range = QutePositionUtility.selectAlias(parameterDeclaration);
                        collector.accept(parameterDeclaration, range);
                    }
                    searchReferencedObjects(alias, PartNameMatcher.BOTH, node, collector, cancelChecker);
                }
                break;
            }
        case Parameter:
            {
                Parameter parameter = (Parameter) node;
                if (includeNode) {
                    Range range = QutePositionUtility.selectParameterName(parameter);
                    collector.accept(parameter, range);
                }
                String alias = parameter.getName();
                searchReferencedObjects(alias, PartNameMatcher.ONLY_NAME, parameter.getParent(), collector, cancelChecker);
                break;
            }
        default:
            break;
    }
}
Also used : RangeOffset(com.redhat.qute.parser.template.RangeOffset) Parameter(com.redhat.qute.parser.template.Parameter) Range(org.eclipse.lsp4j.Range) ParameterDeclaration(com.redhat.qute.parser.template.ParameterDeclaration)

Aggregations

RangeOffset (com.redhat.qute.parser.template.RangeOffset)4 Range (org.eclipse.lsp4j.Range)3 Parameter (com.redhat.qute.parser.template.Parameter)2 ParameterDeclaration (com.redhat.qute.parser.template.ParameterDeclaration)2 QuteJavaDefinitionParams (com.redhat.qute.commons.QuteJavaDefinitionParams)1 ResolvedJavaTypeInfo (com.redhat.qute.commons.ResolvedJavaTypeInfo)1 Expression (com.redhat.qute.parser.template.Expression)1 Node (com.redhat.qute.parser.template.Node)1 JavaTypeRangeOffset (com.redhat.qute.parser.template.ParameterDeclaration.JavaTypeRangeOffset)1 Section (com.redhat.qute.parser.template.Section)1 IncludeSection (com.redhat.qute.parser.template.sections.IncludeSection)1 LoopSection (com.redhat.qute.parser.template.sections.LoopSection)1 DiagnosticDataFactory.createDiagnostic (com.redhat.qute.services.diagnostics.DiagnosticDataFactory.createDiagnostic)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Diagnostic (org.eclipse.lsp4j.Diagnostic)1 Hover (org.eclipse.lsp4j.Hover)1 MarkupContent (org.eclipse.lsp4j.MarkupContent)1