Search in sources :

Example 11 with Template

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

the class QuteAssert method testDocumentLinkFor.

public static void testDocumentLinkFor(String value, String fileUri, String projectUri, String templateBaseDir, DocumentLink... expected) {
    QuteProjectRegistry projectRegistry = new MockQuteProjectRegistry();
    Template template = createTemplate(value, fileUri, projectUri, templateBaseDir, projectRegistry);
    QuteLanguageService languageService = new QuteLanguageService(new JavaDataModelCache(projectRegistry));
    List<DocumentLink> actual = languageService.findDocumentLinks(template);
    assertDocumentLinks(actual, expected);
}
Also used : JavaDataModelCache(com.redhat.qute.project.datamodel.JavaDataModelCache) QuteProjectRegistry(com.redhat.qute.project.QuteProjectRegistry) MockQuteProjectRegistry(com.redhat.qute.project.MockQuteProjectRegistry) QuteLanguageService(com.redhat.qute.services.QuteLanguageService) MockQuteProjectRegistry(com.redhat.qute.project.MockQuteProjectRegistry) DocumentLink(org.eclipse.lsp4j.DocumentLink) Template(com.redhat.qute.parser.template.Template)

Example 12 with Template

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

the class QuteAssert method testReferencesFor.

public static void testReferencesFor(String value, String fileUri, String projectUri, String templateBaseDir, Location... expected) throws BadLocationException {
    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);
    QuteLanguageService languageService = new QuteLanguageService(new JavaDataModelCache(projectRegistry));
    Position position = template.positionAt(offset);
    List<? extends Location> actual = languageService.findReferences(template, position, new ReferenceContext(), () -> {
    });
    assertLocation(actual, expected);
}
Also used : JavaDataModelCache(com.redhat.qute.project.datamodel.JavaDataModelCache) Position(org.eclipse.lsp4j.Position) QuteProjectRegistry(com.redhat.qute.project.QuteProjectRegistry) MockQuteProjectRegistry(com.redhat.qute.project.MockQuteProjectRegistry) ReferenceContext(org.eclipse.lsp4j.ReferenceContext) QuteLanguageService(com.redhat.qute.services.QuteLanguageService) MockQuteProjectRegistry(com.redhat.qute.project.MockQuteProjectRegistry) Template(com.redhat.qute.parser.template.Template)

Example 13 with Template

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

the class QutePositionUtility method selectParameterName.

public static Range selectParameterName(Parameter parameter) {
    Template template = parameter.getOwnerTemplate();
    int startOffset = parameter.getStartName();
    int endOffset = parameter.getEndName();
    return createRange(startOffset, endOffset, template);
}
Also used : Template(com.redhat.qute.parser.template.Template)

Example 14 with Template

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

the class QuteAssert method testHighlightsFor.

public static void testHighlightsFor(String value, String fileUri, String projectUri, String templateBaseDir, DocumentHighlight... expected) throws BadLocationException {
    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);
    QuteLanguageService languageService = new QuteLanguageService(new JavaDataModelCache(projectRegistry));
    Position position = template.positionAt(offset);
    List<? extends DocumentHighlight> actual = languageService.findDocumentHighlights(template, position, () -> {
    });
    assertDocumentHighlight(actual, expected);
}
Also used : JavaDataModelCache(com.redhat.qute.project.datamodel.JavaDataModelCache) Position(org.eclipse.lsp4j.Position) QuteProjectRegistry(com.redhat.qute.project.QuteProjectRegistry) MockQuteProjectRegistry(com.redhat.qute.project.MockQuteProjectRegistry) QuteLanguageService(com.redhat.qute.services.QuteLanguageService) MockQuteProjectRegistry(com.redhat.qute.project.MockQuteProjectRegistry) Template(com.redhat.qute.parser.template.Template)

Example 15 with Template

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

the class QuteCompletionsForSnippets method collectSnippetSuggestions.

/**
 * Collect snippets suggestions.
 *
 * @param completionRequest completion request.
 * @param prefixFilter      prefix filter.
 * @param suffixToFind      suffix to found to eat it when completion snippet is
 *                          applied.
 * @param list              completion list to update.
 */
public void collectSnippetSuggestions(CompletionRequest completionRequest, String prefixFilter, String suffixToFind, CompletionList list) {
    Node node = completionRequest.getNode();
    int offset = completionRequest.getOffset();
    Template template = node.getOwnerTemplate();
    String text = template.getText();
    int endExpr = offset;
    // compute the from for search expression according to the node
    int fromSearchExpr = getExprLimitStart(node, endExpr);
    // compute the start expression
    int startExpr = getExprStart(text, fromSearchExpr, endExpr);
    try {
        Range replaceRange = getReplaceRange(startExpr, endExpr, offset, template);
        String lineDelimiter = template.lineDelimiter(replaceRange.getStart().getLine());
        List<CompletionItem> snippets = getSnippetRegistry().getCompletionItems(replaceRange, lineDelimiter, completionRequest.canSupportMarkupKind(MarkupKind.MARKDOWN), completionRequest.isCompletionSnippetsSupported(), (context, model) -> {
            if (context instanceof IQuteSnippetContext) {
                return (((IQuteSnippetContext) context).isMatch(completionRequest, model));
            }
            return false;
        }, (suffix) -> {
            // Search the suffix from the right of completion offset.
            for (int i = endExpr; i < text.length(); i++) {
                char ch = text.charAt(i);
                if (Character.isWhitespace(ch)) {
                    // whitespace, continue to eat character
                    continue;
                } else {
                    // the current character is not a whitespace, search the suffix index
                    Integer eatIndex = getSuffixIndex(text, suffix, i);
                    if (eatIndex != null) {
                        try {
                            return template.positionAt(eatIndex);
                        } catch (BadLocationException e) {
                            return null;
                        }
                    }
                    return null;
                }
            }
            return null;
        }, suffixToFind, prefixFilter);
        for (CompletionItem completionItem : snippets) {
            list.getItems().add(completionItem);
        }
    } catch (BadLocationException e) {
        LOGGER.log(Level.SEVERE, "In QuteCompletions, collectSnippetSuggestions position error", e);
    }
}
Also used : IQuteSnippetContext(com.redhat.qute.services.snippets.IQuteSnippetContext) CompletionItem(org.eclipse.lsp4j.CompletionItem) Node(com.redhat.qute.parser.template.Node) Range(org.eclipse.lsp4j.Range) BadLocationException(com.redhat.qute.ls.commons.BadLocationException) 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