Search in sources :

Example 1 with Snippet

use of com.redhat.qute.ls.commons.snippets.Snippet 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)

Aggregations

JavaMemberInfo (com.redhat.qute.commons.JavaMemberInfo)1 JavaTypeInfo (com.redhat.qute.commons.JavaTypeInfo)1 ResolvedJavaTypeInfo (com.redhat.qute.commons.ResolvedJavaTypeInfo)1 BadLocationException (com.redhat.qute.ls.commons.BadLocationException)1 Snippet (com.redhat.qute.ls.commons.snippets.Snippet)1 SnippetRegistryProvider (com.redhat.qute.ls.commons.snippets.SnippetRegistryProvider)1 NamespacePart (com.redhat.qute.parser.expression.NamespacePart)1 Part (com.redhat.qute.parser.expression.Part)1 Parts (com.redhat.qute.parser.expression.Parts)1 Expression (com.redhat.qute.parser.template.Expression)1 Node (com.redhat.qute.parser.template.Node)1 Parameter (com.redhat.qute.parser.template.Parameter)1 ParameterDeclaration (com.redhat.qute.parser.template.ParameterDeclaration)1 RangeOffset (com.redhat.qute.parser.template.RangeOffset)1 Section (com.redhat.qute.parser.template.Section)1 SectionKind (com.redhat.qute.parser.template.SectionKind)1 SectionMetadata (com.redhat.qute.parser.template.SectionMetadata)1 Template (com.redhat.qute.parser.template.Template)1 LoopSection (com.redhat.qute.parser.template.sections.LoopSection)1 QuteProject (com.redhat.qute.project.QuteProject)1