Search in sources :

Example 26 with Template

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

the class QuteAssert method testDiagnosticsFor.

public static void testDiagnosticsFor(String value, String fileUri, String templateId, String projectUri, String templateBaseDir, boolean filter, QuteValidationSettings validationSettings, Diagnostic... expected) {
    QuteProjectRegistry projectRegistry = new MockQuteProjectRegistry();
    Template template = createTemplate(value, fileUri, projectUri, templateBaseDir, projectRegistry);
    template.setTemplateId(templateId);
    QuteLanguageService languageService = new QuteLanguageService(new JavaDataModelCache(projectRegistry));
    List<Diagnostic> actual = languageService.doDiagnostics(template, validationSettings, new ResolvingJavaTypeContext(template), () -> {
    });
    if (expected == null) {
        assertTrue(actual.isEmpty());
        return;
    }
    assertDiagnostics(actual, Arrays.asList(expected), filter);
}
Also used : JavaDataModelCache(com.redhat.qute.project.datamodel.JavaDataModelCache) QuteProjectRegistry(com.redhat.qute.project.QuteProjectRegistry) MockQuteProjectRegistry(com.redhat.qute.project.MockQuteProjectRegistry) ResolvingJavaTypeContext(com.redhat.qute.services.diagnostics.ResolvingJavaTypeContext) Diagnostic(org.eclipse.lsp4j.Diagnostic) QuteLanguageService(com.redhat.qute.services.QuteLanguageService) MockQuteProjectRegistry(com.redhat.qute.project.MockQuteProjectRegistry) Template(com.redhat.qute.parser.template.Template)

Example 27 with Template

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

the class QuteAssert method testCodeActionsFor.

private static void testCodeActionsFor(String value, Diagnostic diagnostic, String fileUri, String projectUri, String templateBaseDir, SharedSettings settings, CodeAction... expected) throws Exception {
    int offset = value.indexOf('|');
    Range range = null;
    if (offset != -1) {
        value = value.substring(0, offset) + value.substring(offset + 1);
    }
    TextDocument document = new TextDocument(value.toString(), FILE_URI);
    if (offset != -1) {
        Position position = document.positionAt(offset);
        range = new Range(position, position);
    } else {
        range = diagnostic.getRange();
    }
    CodeActionContext context = new CodeActionContext();
    context.setDiagnostics(Arrays.asList(diagnostic));
    QuteProjectRegistry projectRegistry = new MockQuteProjectRegistry();
    Template template = createTemplate(value, fileUri, projectUri, templateBaseDir, projectRegistry);
    QuteLanguageService languageService = new QuteLanguageService(new JavaDataModelCache(projectRegistry));
    List<CodeAction> actual = languageService.doCodeActions(template, context, range, settings).get();
    assertCodeActions(actual, expected);
}
Also used : JavaDataModelCache(com.redhat.qute.project.datamodel.JavaDataModelCache) TextDocument(com.redhat.qute.ls.commons.TextDocument) CodeActionContext(org.eclipse.lsp4j.CodeActionContext) Position(org.eclipse.lsp4j.Position) QuteProjectRegistry(com.redhat.qute.project.QuteProjectRegistry) MockQuteProjectRegistry(com.redhat.qute.project.MockQuteProjectRegistry) CodeAction(org.eclipse.lsp4j.CodeAction) QuteLanguageService(com.redhat.qute.services.QuteLanguageService) Range(org.eclipse.lsp4j.Range) MockQuteProjectRegistry(com.redhat.qute.project.MockQuteProjectRegistry) Template(com.redhat.qute.parser.template.Template)

Example 28 with Template

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

the class QuteAssert method testCompletionFor.

public static void testCompletionFor(String value, boolean snippetSupport, String fileUri, String templateId, String projectUri, String templateBaseDir, Integer expectedCount, CompletionItem... expectedItems) throws Exception {
    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);
    template.setTemplateId(templateId);
    Position position = template.positionAt(offset);
    // Add snippet support for completion
    QuteCompletionSettings completionSettings = new QuteCompletionSettings();
    CompletionItemCapabilities completionItemCapabilities = new CompletionItemCapabilities();
    completionItemCapabilities.setSnippetSupport(snippetSupport);
    CompletionCapabilities completionCapabilities = new CompletionCapabilities(completionItemCapabilities);
    completionSettings.setCapabilities(completionCapabilities);
    QuteFormattingSettings formattingSettings = new QuteFormattingSettings();
    QuteLanguageService languageService = new QuteLanguageService(new JavaDataModelCache(projectRegistry));
    CompletionList list = languageService.doComplete(template, position, completionSettings, formattingSettings, () -> {
    }).get();
    // no duplicate labels
    List<String> labels = list.getItems().stream().map(i -> i.getLabel()).sorted().collect(Collectors.toList());
    String previous = null;
    for (String label : labels) {
        if (expectedCount != null) {
            continue;
        }
        assertNotEquals(previous, label, () -> {
            return "Duplicate label " + label + " in " + labels.stream().collect(Collectors.joining(",")) + "}";
        });
        previous = label;
    }
    if (expectedCount != null) {
        assertEquals(expectedCount.intValue(), list.getItems().size());
    }
    if (expectedItems != null) {
        for (CompletionItem item : expectedItems) {
            assertCompletion(list, item, expectedCount);
        }
    }
}
Also used : CompletionList(org.eclipse.lsp4j.CompletionList) Position(org.eclipse.lsp4j.Position) QuteProjectRegistry(com.redhat.qute.project.QuteProjectRegistry) MockQuteProjectRegistry(com.redhat.qute.project.MockQuteProjectRegistry) QuteFormattingSettings(com.redhat.qute.settings.QuteFormattingSettings) QuteLanguageService(com.redhat.qute.services.QuteLanguageService) MarkedString(org.eclipse.lsp4j.MarkedString) MockQuteProjectRegistry(com.redhat.qute.project.MockQuteProjectRegistry) Template(com.redhat.qute.parser.template.Template) JavaDataModelCache(com.redhat.qute.project.datamodel.JavaDataModelCache) CompletionItemCapabilities(org.eclipse.lsp4j.CompletionItemCapabilities) QuteCompletionSettings(com.redhat.qute.settings.QuteCompletionSettings) CompletionItem(org.eclipse.lsp4j.CompletionItem) CompletionCapabilities(org.eclipse.lsp4j.CompletionCapabilities)

Example 29 with Template

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

the class QuteAssert method testCodeLensFor.

private static void testCodeLensFor(String value, String fileUri, String templateId, String projectUri, String templateBaseDir, CodeLens... expected) throws Exception {
    QuteProjectRegistry projectRegistry = new MockQuteProjectRegistry();
    Template template = createTemplate(value, fileUri, projectUri, templateBaseDir, projectRegistry);
    template.setTemplateId(templateId);
    QuteLanguageService languageService = new QuteLanguageService(new JavaDataModelCache(projectRegistry));
    SharedSettings sharedSettings = new SharedSettings();
    CommandCapabilities commandCapabilities = new CommandCapabilities();
    CommandKindCapabilities kinds = new CommandKindCapabilities(Arrays.asList(QuteClientCommandConstants.COMMAND_JAVA_DEFINITION));
    commandCapabilities.setCommandKind(kinds);
    sharedSettings.getCommandCapabilities().setCapabilities(commandCapabilities);
    List<? extends CodeLens> actual = languageService.getCodeLens(template, sharedSettings, () -> {
    }).get();
    assertCodeLens(actual, expected);
}
Also used : JavaDataModelCache(com.redhat.qute.project.datamodel.JavaDataModelCache) SharedSettings(com.redhat.qute.settings.SharedSettings) QuteProjectRegistry(com.redhat.qute.project.QuteProjectRegistry) MockQuteProjectRegistry(com.redhat.qute.project.MockQuteProjectRegistry) CommandCapabilities(com.redhat.qute.ls.commons.client.CommandCapabilities) QuteLanguageService(com.redhat.qute.services.QuteLanguageService) CommandKindCapabilities(com.redhat.qute.ls.commons.client.CommandKindCapabilities) MockQuteProjectRegistry(com.redhat.qute.project.MockQuteProjectRegistry) 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