Search in sources :

Example 6 with QuteIndex

use of com.redhat.qute.project.indexing.QuteIndex in project quarkus-ls by redhat-developer.

the class QuteProject method collectInsert.

private void collectInsert(String insertParamater, Node parent, Template template, List<QuteIndex> indexes) {
    if (parent.getKind() == NodeKind.Section) {
        Section section = (Section) parent;
        if (section.getSectionKind() == SectionKind.INSERT) {
            Parameter parameter = section.getParameterAtIndex(0);
            if (parameter != null) {
                try {
                    if (insertParamater == null || insertParamater.equals(parameter.getValue())) {
                        Position position = template.positionAt(parameter.getStart());
                        Path path = createPath(template.getUri());
                        QuteTemplateIndex templateIndex = new QuteTemplateIndex(path, template.getTemplateId());
                        QuteIndex index = new QuteIndex("insert", parameter.getValue(), position, SectionKind.INSERT, templateIndex);
                        indexes.add(index);
                    }
                } catch (BadLocationException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    List<Node> children = parent.getChildren();
    for (Node node : children) {
        collectInsert(insertParamater, node, template, indexes);
    }
}
Also used : Path(java.nio.file.Path) FileUtils.createPath(com.redhat.qute.utils.FileUtils.createPath) QuteTemplateIndex(com.redhat.qute.project.indexing.QuteTemplateIndex) Position(org.eclipse.lsp4j.Position) Node(com.redhat.qute.parser.template.Node) QuteIndex(com.redhat.qute.project.indexing.QuteIndex) Parameter(com.redhat.qute.parser.template.Parameter) DataModelParameter(com.redhat.qute.commons.datamodel.DataModelParameter) Section(com.redhat.qute.parser.template.Section) BadLocationException(com.redhat.qute.ls.commons.BadLocationException)

Example 7 with QuteIndex

use of com.redhat.qute.project.indexing.QuteIndex in project quarkus-ls by redhat-developer.

the class QuteIndexerTest method definition.

@Test
public void definition() {
    long start = System.currentTimeMillis();
    QuteIndexer indexer = new QuteIndexer(createProject());
    indexer.scan();
    long end = System.currentTimeMillis();
    System.err.println((end - start) + "ms");
    // base.qute.html -->
    // <title>{#insert title}Default Title{/}</title>
    // BookPage/book.qute.html -->
    // {#include base.qute.html}
    // {#ti|tle}A Book{/title}
    // get definition of title parameter of insert, declared in'base.qute.html'
    List<QuteIndex> indexes = indexer.find("base.qute.html", "insert", "title");
    assertNotNull(indexes);
    assertEquals(1, indexes.size());
    QuteIndex index = indexes.get(0);
    assertEquals(// 
    "QuteIndex [\n" + // 
    "  tag = \"insert\"\n" + // 
    "  parameter = \"title\"\n" + // 
    "  position = Position [\n" + // 
    "    line = 3\n" + // 
    "    character = 18\n" + // 
    "  ]\n" + // 
    "  kind = INSERT\n" + // 
    "  templateId = \"base.qute.html\"\n" + "]", index.toString());
}
Also used : QuteIndex(com.redhat.qute.project.indexing.QuteIndex) QuteIndexer(com.redhat.qute.project.indexing.QuteIndexer) Test(org.junit.jupiter.api.Test)

Example 8 with QuteIndex

use of com.redhat.qute.project.indexing.QuteIndex in project quarkus-ls by redhat-developer.

the class QuteIndexerTest method referencesOfIncludedFile.

@Test
public void referencesOfIncludedFile() {
    long start = System.currentTimeMillis();
    QuteIndexer indexer = new QuteIndexer(createProject());
    indexer.scan();
    long end = System.currentTimeMillis();
    System.err.println((end - start) + "ms");
    // base.qute.html -->
    // <title>{#insert title}Default Title{/}</title>
    // ...
    // {#insert body}No body!{/}
    // 1. reference
    // BookPage/book.qute.html -->
    // {#include base}
    // {#title}A Book{/title}
    // 2. reference
    // BookPage/books.qute.html -->
    // {#include base}
    // {#title}Books{/title}
    List<QuteIndex> indexes = indexer.find(null, "include", "base");
    assertNotNull(indexes);
    assertEquals(2, indexes.size());
    assertEquals(// 
    "[QuteIndex [\n" + // 
    "  tag = \"include\"\n" + // 
    "  parameter = \"base\"\n" + // 
    "  position = Position [\n" + // 
    "    line = 0\n" + // 
    "    character = 10\n" + // 
    "  ]\n" + // 
    "  kind = INCLUDE\n" + // 
    "  templateId = \"BookPage/books.qute.html\"\n" + // 
    "], QuteIndex [\n" + // 
    "  tag = \"include\"\n" + // 
    "  parameter = \"base\"\n" + // 
    "  position = Position [\n" + // 
    "    line = 0\n" + // 
    "    character = 10\n" + // 
    "  ]\n" + // 
    "  kind = INCLUDE\n" + // 
    "  templateId = \"BookPage/book.qute.html\"\n" + "]]", indexes.toString());
}
Also used : QuteIndex(com.redhat.qute.project.indexing.QuteIndex) QuteIndexer(com.redhat.qute.project.indexing.QuteIndexer) Test(org.junit.jupiter.api.Test)

Aggregations

QuteIndex (com.redhat.qute.project.indexing.QuteIndex)8 QuteIndexer (com.redhat.qute.project.indexing.QuteIndexer)4 Test (org.junit.jupiter.api.Test)4 Node (com.redhat.qute.parser.template.Node)3 Section (com.redhat.qute.parser.template.Section)3 IncludeSection (com.redhat.qute.parser.template.sections.IncludeSection)2 QuteProject (com.redhat.qute.project.QuteProject)2 UserTag (com.redhat.qute.project.tags.UserTag)2 Position (org.eclipse.lsp4j.Position)2 Range (org.eclipse.lsp4j.Range)2 DataModelParameter (com.redhat.qute.commons.datamodel.DataModelParameter)1 DataModelTemplate (com.redhat.qute.commons.datamodel.DataModelTemplate)1 BadLocationException (com.redhat.qute.ls.commons.BadLocationException)1 Parameter (com.redhat.qute.parser.template.Parameter)1 SectionKind (com.redhat.qute.parser.template.SectionKind)1 Template (com.redhat.qute.parser.template.Template)1 LoopSection (com.redhat.qute.parser.template.sections.LoopSection)1 QuteTemplateIndex (com.redhat.qute.project.indexing.QuteTemplateIndex)1 DiagnosticDataFactory.createDiagnostic (com.redhat.qute.services.diagnostics.DiagnosticDataFactory.createDiagnostic)1 FileUtils.createPath (com.redhat.qute.utils.FileUtils.createPath)1