Search in sources :

Example 1 with Template

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

the class QuteProject method findInsertTagParameter.

public List<QuteIndex> findInsertTagParameter(String templateId, String insertParamater) {
    TemplateProvider provider = openedDocuments.get(templateId);
    if (provider != null) {
        Template template = provider.getTemplate().getNow(null);
        if (template != null) {
            List<QuteIndex> indexes = new ArrayList<>();
            collectInsert(insertParamater, template, template, indexes);
            return indexes;
        }
        return Collections.emptyList();
    }
    indexer.scanAsync();
    return indexer.find(templateId, "insert", insertParamater);
}
Also used : QuteIndex(com.redhat.qute.project.indexing.QuteIndex) ArrayList(java.util.ArrayList) Template(com.redhat.qute.parser.template.Template) DataModelTemplate(com.redhat.qute.commons.datamodel.DataModelTemplate)

Example 2 with Template

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

the class QuteHover method doHoverForSection.

private CompletableFuture<Hover> doHoverForSection(Section section, Template template, HoverRequest hoverRequest, CancelChecker cancelChecker) {
    if (section.hasTag()) {
        // the section defines a tag (e : {#for
        String tagName = section.getTag();
        if (section.getSectionKind() == SectionKind.CUSTOM) {
            // custom tag: search information about user tag
            QuteProject project = template.getProject();
            if (project != null) {
                UserTag userTag = project.findUserTag(tagName);
                if (userTag != null) {
                    Range range = createSectionTagRange(section, hoverRequest);
                    if (range != null) {
                        boolean hasMarkdown = hoverRequest.canSupportMarkupKind(MarkupKind.MARKDOWN);
                        MarkupContent content = DocumentationUtils.getDocumentation(userTag, hasMarkdown);
                        Hover hover = new Hover(content, range);
                        return CompletableFuture.completedFuture(hover);
                    }
                }
            }
        } else {
            // core tag like #for, #if, etc: display document hover for the section
            Optional<Snippet> snippetSection = // 
            snippetRegistryProvider.getSnippetRegistry().getSnippets().stream().filter(// 
            snippet -> tagName.equals(snippet.getLabel())).findFirst();
            if (snippetSection.isPresent()) {
                Snippet snippet = snippetSection.get();
                Range range = createSectionTagRange(section, hoverRequest);
                if (range != null) {
                    boolean hasMarkdown = hoverRequest.canSupportMarkupKind(MarkupKind.MARKDOWN);
                    MarkupContent content = DocumentationUtils.getDocumentation(snippet, hasMarkdown);
                    Hover hover = new Hover(content, range);
                    return CompletableFuture.completedFuture(hover);
                }
            }
        }
    }
    return NO_HOVER;
}
Also used : Template(com.redhat.qute.parser.template.Template) LoopSection(com.redhat.qute.parser.template.sections.LoopSection) MarkupKind(org.eclipse.lsp4j.MarkupKind) UserTagUtils(com.redhat.qute.utils.UserTagUtils) SectionMetadata(com.redhat.qute.parser.template.SectionMetadata) QutePositionUtility(com.redhat.qute.utils.QutePositionUtility) CompletableFuture(java.util.concurrent.CompletableFuture) Range(org.eclipse.lsp4j.Range) QuteProject(com.redhat.qute.project.QuteProject) Hover(org.eclipse.lsp4j.Hover) SnippetRegistryProvider(com.redhat.qute.ls.commons.snippets.SnippetRegistryProvider) Level(java.util.logging.Level) Parameter(com.redhat.qute.parser.template.Parameter) JavaDataModelCache(com.redhat.qute.project.datamodel.JavaDataModelCache) UserTag(com.redhat.qute.project.tags.UserTag) SectionKind(com.redhat.qute.parser.template.SectionKind) Expression(com.redhat.qute.parser.template.Expression) Section(com.redhat.qute.parser.template.Section) Parts(com.redhat.qute.parser.expression.Parts) Position(org.eclipse.lsp4j.Position) JavaMemberInfo(com.redhat.qute.commons.JavaMemberInfo) Snippet(com.redhat.qute.ls.commons.snippets.Snippet) DocumentationUtils(com.redhat.qute.utils.DocumentationUtils) MarkupContent(org.eclipse.lsp4j.MarkupContent) NamespacePart(com.redhat.qute.parser.expression.NamespacePart) Node(com.redhat.qute.parser.template.Node) JavaTypeInfo(com.redhat.qute.commons.JavaTypeInfo) Logger(java.util.logging.Logger) CancelChecker(org.eclipse.lsp4j.jsonrpc.CancelChecker) HoverRequest(com.redhat.qute.services.hover.HoverRequest) BadLocationException(com.redhat.qute.ls.commons.BadLocationException) Part(com.redhat.qute.parser.expression.Part) ParameterDeclaration(com.redhat.qute.parser.template.ParameterDeclaration) SharedSettings(com.redhat.qute.settings.SharedSettings) RangeOffset(com.redhat.qute.parser.template.RangeOffset) ResolvedJavaTypeInfo(com.redhat.qute.commons.ResolvedJavaTypeInfo) Optional(java.util.Optional) Hover(org.eclipse.lsp4j.Hover) QuteProject(com.redhat.qute.project.QuteProject) Snippet(com.redhat.qute.ls.commons.snippets.Snippet) UserTag(com.redhat.qute.project.tags.UserTag) Range(org.eclipse.lsp4j.Range) MarkupContent(org.eclipse.lsp4j.MarkupContent)

Example 3 with Template

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

the class QuteCompletionForTagSection method doCompleteTagSection.

public void doCompleteTagSection(CompletionRequest completionRequest, String filterPrefix, QuteCompletionSettings completionSettings, QuteFormattingSettings formattingSettings, CancelChecker cancelChecker, CompletionList list) {
    // Completion for user tags
    Template template = completionRequest.getTemplate();
    QuteProject project = template.getProject();
    if (project != null) {
        project.collectUserTagSuggestions(completionRequest, filterPrefix, "}", list);
    }
    // Completion for #for, #if, etc
    completionsForSnippets.collectSnippetSuggestions(completionRequest, filterPrefix, "}", list);
}
Also used : QuteProject(com.redhat.qute.project.QuteProject) Template(com.redhat.qute.parser.template.Template)

Example 4 with Template

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

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

the class QutePositionUtility method selectAlias.

public static Range selectAlias(ParameterDeclaration parameter) {
    Template template = parameter.getOwnerTemplate();
    int startOffset = parameter.getAliasStart();
    int endOffset = parameter.getAliasEnd();
    return createRange(startOffset, endOffset, template);
}
Also used : Template(com.redhat.qute.parser.template.Template)

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