use of com.redhat.qute.parser.template.Section in project quarkus-ls by redhat-developer.
the class QuteHighlighting method higlightSection.
private static void higlightSection(Section section, int offset, Position position, List<DocumentHighlight> highlights, CancelChecker cancelChecker) throws BadLocationException {
if (section.isInStartTagName(offset) || section.isInEndTagName(offset)) {
highlightSectionTag(section, highlights);
if (!section.getBlockLabels().isEmpty()) {
// The section can have nested block (ex #for can have #else)
for (Node node : section.getChildren()) {
if (node.getKind() == NodeKind.Section && section.getBlockLabels().contains(((Section) node).getSectionKind())) {
Section nestedBlock = (Section) node;
highlightSectionTag(nestedBlock, highlights);
}
}
} else {
// Get parent section
Section parentSection = section.getParentSection();
if (parentSection != null && parentSection.getBlockLabels().contains(section.getSectionKind())) {
highlightSectionTag(parentSection, highlights);
}
}
} else {
highlightReferenceObjectPart(section, offset, highlights, cancelChecker);
}
}
use of com.redhat.qute.parser.template.Section in project quarkus-ls by redhat-developer.
the class QuteHover method doHover.
public CompletableFuture<Hover> doHover(Template template, Position position, SharedSettings settings, CancelChecker cancelChecker) {
cancelChecker.checkCanceled();
HoverRequest hoverRequest = null;
try {
hoverRequest = new HoverRequest(template, position, settings);
} catch (BadLocationException e) {
LOGGER.log(Level.SEVERE, "Failed creating HoverRequest", e);
return NO_HOVER;
}
Node node = hoverRequest.getNode();
if (node == null) {
return NO_HOVER;
}
switch(node.getKind()) {
case Section:
// - Start end tag definition
Section section = (Section) node;
return doHoverForSection(section, template, hoverRequest, cancelChecker);
case ParameterDeclaration:
ParameterDeclaration parameterDeclaration = (ParameterDeclaration) node;
return doHoverForParameterDeclaration(parameterDeclaration, template, hoverRequest, cancelChecker);
case ExpressionPart:
Part part = (Part) node;
return doHoverForExpressionPart(part, template, hoverRequest, cancelChecker);
case Parameter:
Parameter parameter = (Parameter) node;
return doHoverForParameter(parameter, template, hoverRequest);
default:
return NO_HOVER;
}
}
use of com.redhat.qute.parser.template.Section in project quarkus-ls by redhat-developer.
the class UserTagUtils method collectUserTagParameters.
private static void collectUserTagParameters(Node parent, Template template, Set<String> extistingObjectParts, Consumer<ObjectPart> collector, CancelChecker cancelChecker) {
cancelChecker.checkCanceled();
if (parent.getKind() == NodeKind.Expression) {
Expression expression = (Expression) parent;
collectUserTagParameters(expression, extistingObjectParts, collector, cancelChecker);
return;
} else if (parent.getKind() == NodeKind.Section) {
Section section = (Section) parent;
List<Parameter> parameters = section.getParameters();
for (Parameter parameter : parameters) {
if (parameter.isCanHaveExpression()) {
Expression expression = parameter.getJavaTypeExpression();
collectUserTagParameters(expression, extistingObjectParts, collector, cancelChecker);
}
}
}
List<Node> children = parent.getChildren();
for (Node node : children) {
collectUserTagParameters(node, template, extistingObjectParts, collector, cancelChecker);
}
}
use of com.redhat.qute.parser.template.Section in project quarkus-ls by redhat-developer.
the class QuteSearchUtils method searchDeclaredObjectInParameter.
private static Parameter searchDeclaredObjectInParameter(ObjectPart part, CancelChecker cancelChecker) {
String partName = part.getPartName();
Node parent = part.getParentSection();
while (parent != null) {
if (parent.getKind() == NodeKind.Section) {
Section section = (Section) parent;
switch(section.getSectionKind()) {
case EACH:
case FOR:
LoopSection iterableSection = (LoopSection) section;
if (!iterableSection.isInElseBlock(part.getStart())) {
String alias = iterableSection.getAlias();
if (partName.equals(alias) || section.isMetadata(partName)) {
// - or the metadata of the section (ex : item_count)
return iterableSection.getAliasParameter();
}
}
break;
case LET:
case SET:
List<Parameter> parameters = section.getParameters();
for (Parameter parameter : parameters) {
if (partName.equals(parameter.getName())) {
return parameter;
}
}
break;
default:
}
}
parent = parent.getParent();
}
return null;
}
use of com.redhat.qute.parser.template.Section in project quarkus-ls by redhat-developer.
the class QuteSearchUtils method tryToCollectObjectPartOrParameter.
public static void tryToCollectObjectPartOrParameter(String partName, PartNameMatcher matcher, Expression expression, Node ownerNode, BiConsumer<Node, Range> collector) {
// object part)
if (!tryToCollectObjectParts(partName, matcher, expression, collector)) {
if (ownerNode.getKind() == NodeKind.Section) {
Section onwerSection = (Section) ownerNode;
// Check the current expression references a metadata of the section
ObjectPart objectPart = expression.getObjectPart();
if (objectPart != null) {
JavaTypeInfoProvider metadata = onwerSection.getMetadata(objectPart.getPartName());
if (metadata != null) {
// Adjust the object part range with the given part name
// Example if expression is like {item_count}
// Range should be {|item|_count}
Range range = QutePositionUtility.createRange(objectPart.getStart(), objectPart.getStart() + partName.length(), objectPart.getOwnerTemplate());
collector.accept(objectPart, range);
}
}
}
}
}
Aggregations