use of com.redhat.qute.parser.template.Template in project quarkus-ls by redhat-developer.
the class QuteReference method findReferences.
public List<? extends Location> findReferences(Template template, Position position, ReferenceContext context, CancelChecker cancelChecker) {
try {
int offset = template.offsetAt(position);
Node node = template.findNodeAt(offset);
if (node == null) {
return Collections.emptyList();
}
node = QutePositionUtility.findBestNode(offset, node);
List<Location> locations = new ArrayList<>();
//
QuteSearchUtils.searchReferencedObjects(//
node, //
offset, (n, range) -> {
Template targetDocument = n.getOwnerTemplate();
Range targetRange = QutePositionUtility.createRange(n.getStart(), n.getEnd(), targetDocument);
Location location = new Location(targetDocument.getUri(), targetRange);
locations.add(location);
}, false, cancelChecker);
return locations;
} catch (BadLocationException e) {
LOGGER.log(Level.SEVERE, "In QuteReference the client provided Position is at a BadLocation", e);
return Collections.emptyList();
}
}
use of com.redhat.qute.parser.template.Template in project quarkus-ls by redhat-developer.
the class ObjectPart method resolveJavaType.
public JavaTypeInfoProvider resolveJavaType() {
Template template = super.getOwnerTemplate();
String partName = getPartName();
boolean hasNamespace = getNamespace() != null;
if (hasNamespace) {
// ex : {data:item}
return template.findWithNamespace(this);
}
// ex : {item}
// Loop for parent section to discover the class name
Section section = super.getParentSection();
while (section != null) {
switch(section.getSectionKind()) {
case EACH:
case FOR:
LoopSection iterableSection = (LoopSection) section;
if (!iterableSection.isInElseBlock(getStart())) {
String alias = iterableSection.getAlias();
if (partName.equals(alias)) {
return iterableSection.getIterableParameter();
}
}
break;
case LET:
case SET:
List<Parameter> parameters = section.getParameters();
for (Parameter parameter : parameters) {
if (partName.equals(parameter.getName())) {
return parameter;
}
}
break;
default:
}
// ex : count for #each
JavaTypeInfoProvider metadata = section.getMetadata(partName);
if (metadata != null) {
return metadata;
}
section = section.getParentSection();
}
// - from @CheckedTemplate
return template.findInInitialDataModel(this);
}
use of com.redhat.qute.parser.template.Template in project quarkus-ls by redhat-developer.
the class QuteCompletions method collectSnippetSuggestions.
private CompletableFuture<CompletionList> collectSnippetSuggestions(CompletionRequest completionRequest) {
CompletionList list = new CompletionList();
Template template = completionRequest.getTemplate();
QuteProject project = template.getProject();
if (project != null) {
project.collectUserTagSuggestions(completionRequest, "", null, list);
}
completionsForSnippets.collectSnippetSuggestions(completionRequest, "", null, list);
return CompletableFuture.completedFuture(list);
}
use of com.redhat.qute.parser.template.Template in project quarkus-ls by redhat-developer.
the class QuteSearchUtils method searchReferencedObjects.
private static void searchReferencedObjects(String partName, PartNameMatcher matcher, Node owerNode, BiConsumer<Node, Range> collector, CancelChecker cancelChecker) {
Template template = owerNode.getOwnerTemplate();
Node parent = owerNode.getKind() == NodeKind.ParameterDeclaration ? template : owerNode;
searchReferencedObjects(partName, matcher, parent, owerNode, collector, cancelChecker);
}
use of com.redhat.qute.parser.template.Template in project quarkus-ls by redhat-developer.
the class QuteAssert method testLinkedEditingFor.
public static void testLinkedEditingFor(String value, String fileUri, String projectUri, String templateBaseDir, LinkedEditingRanges 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);
LinkedEditingRanges actual = languageService.findLinkedEditingRanges(template, position, () -> {
});
assertLinkedEditing(actual, expected);
}
Aggregations