Search in sources :

Example 16 with Template

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

the class QuteReference method findReferences.

public List<? extends Location> findReferences(Template template, Position position, ReferenceContext context, CancelChecker cancelChecker) {
    try {
        int offset = template.offsetAt(position);
        Node node = template.findNodeAt(offset);
        if (node == null) {
            return Collections.emptyList();
        }
        node = QutePositionUtility.findBestNode(offset, node);
        List<Location> locations = new ArrayList<>();
        // 
        QuteSearchUtils.searchReferencedObjects(// 
        node, // 
        offset, (n, range) -> {
            Template targetDocument = n.getOwnerTemplate();
            Range targetRange = QutePositionUtility.createRange(n.getStart(), n.getEnd(), targetDocument);
            Location location = new Location(targetDocument.getUri(), targetRange);
            locations.add(location);
        }, false, cancelChecker);
        return locations;
    } catch (BadLocationException e) {
        LOGGER.log(Level.SEVERE, "In QuteReference the client provided Position is at a BadLocation", e);
        return Collections.emptyList();
    }
}
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) Location(org.eclipse.lsp4j.Location) Template(com.redhat.qute.parser.template.Template)

Example 17 with Template

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

the class ObjectPart method resolveJavaType.

public JavaTypeInfoProvider resolveJavaType() {
    Template template = super.getOwnerTemplate();
    String partName = getPartName();
    boolean hasNamespace = getNamespace() != null;
    if (hasNamespace) {
        // ex : {data:item}
        return template.findWithNamespace(this);
    }
    // ex : {item}
    // Loop for parent section to discover the class name
    Section section = super.getParentSection();
    while (section != null) {
        switch(section.getSectionKind()) {
            case EACH:
            case FOR:
                LoopSection iterableSection = (LoopSection) section;
                if (!iterableSection.isInElseBlock(getStart())) {
                    String alias = iterableSection.getAlias();
                    if (partName.equals(alias)) {
                        return iterableSection.getIterableParameter();
                    }
                }
                break;
            case LET:
            case SET:
                List<Parameter> parameters = section.getParameters();
                for (Parameter parameter : parameters) {
                    if (partName.equals(parameter.getName())) {
                        return parameter;
                    }
                }
                break;
            default:
        }
        // ex : count for #each
        JavaTypeInfoProvider metadata = section.getMetadata(partName);
        if (metadata != null) {
            return metadata;
        }
        section = section.getParentSection();
    }
    // - from @CheckedTemplate
    return template.findInInitialDataModel(this);
}
Also used : JavaTypeInfoProvider(com.redhat.qute.parser.template.JavaTypeInfoProvider) LoopSection(com.redhat.qute.parser.template.sections.LoopSection) Parameter(com.redhat.qute.parser.template.Parameter) LoopSection(com.redhat.qute.parser.template.sections.LoopSection) Section(com.redhat.qute.parser.template.Section) Template(com.redhat.qute.parser.template.Template)

Example 18 with Template

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

the class QuteCompletions method collectSnippetSuggestions.

private CompletableFuture<CompletionList> collectSnippetSuggestions(CompletionRequest completionRequest) {
    CompletionList list = new CompletionList();
    Template template = completionRequest.getTemplate();
    QuteProject project = template.getProject();
    if (project != null) {
        project.collectUserTagSuggestions(completionRequest, "", null, list);
    }
    completionsForSnippets.collectSnippetSuggestions(completionRequest, "", null, list);
    return CompletableFuture.completedFuture(list);
}
Also used : CompletionList(org.eclipse.lsp4j.CompletionList) QuteProject(com.redhat.qute.project.QuteProject) Template(com.redhat.qute.parser.template.Template)

Example 19 with Template

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

the class QuteSearchUtils method searchReferencedObjects.

private static void searchReferencedObjects(String partName, PartNameMatcher matcher, Node owerNode, BiConsumer<Node, Range> collector, CancelChecker cancelChecker) {
    Template template = owerNode.getOwnerTemplate();
    Node parent = owerNode.getKind() == NodeKind.ParameterDeclaration ? template : owerNode;
    searchReferencedObjects(partName, matcher, parent, owerNode, collector, cancelChecker);
}
Also used : Node(com.redhat.qute.parser.template.Node) Template(com.redhat.qute.parser.template.Template)

Example 20 with Template

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

the class QuteAssert method testLinkedEditingFor.

public static void testLinkedEditingFor(String value, String fileUri, String projectUri, String templateBaseDir, LinkedEditingRanges expected) throws BadLocationException {
    int offset = value.indexOf('|');
    value = value.substring(0, offset) + value.substring(offset + 1);
    QuteProjectRegistry projectRegistry = new MockQuteProjectRegistry();
    Template template = createTemplate(value, fileUri, projectUri, templateBaseDir, projectRegistry);
    QuteLanguageService languageService = new QuteLanguageService(new JavaDataModelCache(projectRegistry));
    Position position = template.positionAt(offset);
    LinkedEditingRanges actual = languageService.findLinkedEditingRanges(template, position, () -> {
    });
    assertLinkedEditing(actual, expected);
}
Also used : JavaDataModelCache(com.redhat.qute.project.datamodel.JavaDataModelCache) Position(org.eclipse.lsp4j.Position) QuteProjectRegistry(com.redhat.qute.project.QuteProjectRegistry) MockQuteProjectRegistry(com.redhat.qute.project.MockQuteProjectRegistry) QuteLanguageService(com.redhat.qute.services.QuteLanguageService) MockQuteProjectRegistry(com.redhat.qute.project.MockQuteProjectRegistry) Template(com.redhat.qute.parser.template.Template) LinkedEditingRanges(org.eclipse.lsp4j.LinkedEditingRanges)

Aggregations

Template (com.redhat.qute.parser.template.Template)29 JavaDataModelCache (com.redhat.qute.project.datamodel.JavaDataModelCache)13 MockQuteProjectRegistry (com.redhat.qute.project.MockQuteProjectRegistry)11 QuteProjectRegistry (com.redhat.qute.project.QuteProjectRegistry)11 QuteLanguageService (com.redhat.qute.services.QuteLanguageService)11 Position (org.eclipse.lsp4j.Position)8 Node (com.redhat.qute.parser.template.Node)6 Range (org.eclipse.lsp4j.Range)6 ArrayList (java.util.ArrayList)5 Parameter (com.redhat.qute.parser.template.Parameter)4 BadLocationException (com.redhat.qute.ls.commons.BadLocationException)3 Section (com.redhat.qute.parser.template.Section)3 LoopSection (com.redhat.qute.parser.template.sections.LoopSection)3 QuteProject (com.redhat.qute.project.QuteProject)3 CompletionItem (org.eclipse.lsp4j.CompletionItem)3 ResolvedJavaTypeInfo (com.redhat.qute.commons.ResolvedJavaTypeInfo)2 NamespacePart (com.redhat.qute.parser.expression.NamespacePart)2 Part (com.redhat.qute.parser.expression.Part)2 Parts (com.redhat.qute.parser.expression.Parts)2 Expression (com.redhat.qute.parser.template.Expression)2