Search in sources :

Example 1 with QuteCompletionSettings

use of com.redhat.qute.settings.QuteCompletionSettings 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)

Aggregations

Template (com.redhat.qute.parser.template.Template)1 MockQuteProjectRegistry (com.redhat.qute.project.MockQuteProjectRegistry)1 QuteProjectRegistry (com.redhat.qute.project.QuteProjectRegistry)1 JavaDataModelCache (com.redhat.qute.project.datamodel.JavaDataModelCache)1 QuteLanguageService (com.redhat.qute.services.QuteLanguageService)1 QuteCompletionSettings (com.redhat.qute.settings.QuteCompletionSettings)1 QuteFormattingSettings (com.redhat.qute.settings.QuteFormattingSettings)1 CompletionCapabilities (org.eclipse.lsp4j.CompletionCapabilities)1 CompletionItem (org.eclipse.lsp4j.CompletionItem)1 CompletionItemCapabilities (org.eclipse.lsp4j.CompletionItemCapabilities)1 CompletionList (org.eclipse.lsp4j.CompletionList)1 MarkedString (org.eclipse.lsp4j.MarkedString)1 Position (org.eclipse.lsp4j.Position)1