Search in sources :

Example 1 with SectionKind

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

the class QuteTemplateIndex method collect.

private void collect(String template, List<QuteIndex> indexes) {
    Scanner<TokenType, ScannerState> scanner = TemplateScanner.createScanner(template);
    TokenType token = scanner.scan();
    String lastTag = null;
    int lastTokenOffset = -1;
    SectionKind lastSectionKind = null;
    while (token != TokenType.EOS) {
        switch(token) {
            case StartTag:
                {
                    String tag = scanner.getTokenText();
                    if (SectionKind.INCLUDE.name().toLowerCase().equals(tag)) {
                        lastTag = tag;
                        lastTokenOffset = scanner.getTokenOffset();
                        lastSectionKind = SectionKind.INCLUDE;
                    } else if (SectionKind.INSERT.name().toLowerCase().equals(tag)) {
                        lastTag = tag;
                        lastTokenOffset = scanner.getTokenOffset();
                        lastSectionKind = SectionKind.INSERT;
                    } else if (isCustomTag(tag)) {
                        collectIndex(scanner.getTokenOffset(), SectionKind.CUSTOM, scanner.getTokenText(), null, template, indexes);
                    }
                    break;
                }
            case ParameterTag:
                {
                    if (lastSectionKind != null) {
                        String parameter = scanner.getTokenText();
                        collectIndex(scanner.getTokenOffset(), lastSectionKind, lastTag, parameter, template, indexes);
                        lastTokenOffset = -1;
                        lastSectionKind = null;
                        lastTag = null;
                    }
                    break;
                }
            case Whitespace:
                {
                    break;
                }
            default:
                if (lastSectionKind != null) {
                    collectIndex(lastTokenOffset, lastSectionKind, lastTag, null, template, indexes);
                    lastTokenOffset = -1;
                    lastSectionKind = null;
                    lastTag = null;
                }
        }
        token = scanner.scan();
    }
}
Also used : SectionKind(com.redhat.qute.parser.template.SectionKind) TokenType(com.redhat.qute.parser.template.scanner.TokenType) ScannerState(com.redhat.qute.parser.template.scanner.ScannerState)

Example 2 with SectionKind

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

the class QuteDiagnostics method validateSectionTag.

private static void validateSectionTag(Section section, Template template, ResolvingJavaTypeContext resolvingJavaTypeContext, List<Diagnostic> diagnostics) {
    String tagName = section.getTag();
    if (StringUtils.isEmpty(tagName)) {
        return;
    }
    SectionKind sectionKind = section.getSectionKind();
    if (sectionKind == SectionKind.CUSTOM) {
        if (!resolvingJavaTypeContext.isBinaryUserTagResolved()) {
            // Don't validate custom tag, if the binary user tags are not loaded.
            return;
        }
        QuteProject project = template.getProject();
        if (project != null) {
            // Check if section tag is an user tag
            UserTag userTag = project.findUserTag(tagName);
            if (userTag != null) {
                return;
            }
            // Check if section tag is a parameter from an include section
            Node parent = section.getParent();
            while (parent != null) {
                if (parent.getKind() == NodeKind.Section) {
                    Section parentSection = (Section) parent;
                    if (parentSection.getSectionKind() == SectionKind.INCLUDE) {
                        IncludeSection includeSection = (IncludeSection) parentSection;
                        List<QuteIndex> indexes = project.findInsertTagParameter(includeSection.getReferencedTemplateId(), tagName);
                        if (indexes != null) {
                            return;
                        }
                    }
                }
                parent = parent.getParent();
            }
            Range range = QutePositionUtility.selectStartTagName(section);
            Diagnostic diagnostic = createDiagnostic(range, DiagnosticSeverity.Error, QuteErrorCode.UndefinedSectionTag, tagName);
            // Create data information helpful for code action
            diagnostic.setData(DiagnosticDataFactory.createUndefinedSectionTagData(tagName));
            diagnostics.add(diagnostic);
        }
    }
}
Also used : SectionKind(com.redhat.qute.parser.template.SectionKind) Node(com.redhat.qute.parser.template.Node) QuteIndex(com.redhat.qute.project.indexing.QuteIndex) IncludeSection(com.redhat.qute.parser.template.sections.IncludeSection) DiagnosticDataFactory.createDiagnostic(com.redhat.qute.services.diagnostics.DiagnosticDataFactory.createDiagnostic) Diagnostic(org.eclipse.lsp4j.Diagnostic) QuteProject(com.redhat.qute.project.QuteProject) UserTag(com.redhat.qute.project.tags.UserTag) 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)

Aggregations

SectionKind (com.redhat.qute.parser.template.SectionKind)2 Node (com.redhat.qute.parser.template.Node)1 Section (com.redhat.qute.parser.template.Section)1 ScannerState (com.redhat.qute.parser.template.scanner.ScannerState)1 TokenType (com.redhat.qute.parser.template.scanner.TokenType)1 IncludeSection (com.redhat.qute.parser.template.sections.IncludeSection)1 LoopSection (com.redhat.qute.parser.template.sections.LoopSection)1 QuteProject (com.redhat.qute.project.QuteProject)1 QuteIndex (com.redhat.qute.project.indexing.QuteIndex)1 UserTag (com.redhat.qute.project.tags.UserTag)1 DiagnosticDataFactory.createDiagnostic (com.redhat.qute.services.diagnostics.DiagnosticDataFactory.createDiagnostic)1 Diagnostic (org.eclipse.lsp4j.Diagnostic)1 Range (org.eclipse.lsp4j.Range)1