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);
}
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);
}
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);
}
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);
}
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);
}
}
Aggregations