use of com.redhat.qute.parser.template.Parameter in project quarkus-ls by redhat-developer.
the class SwitchSection method accept0.
@Override
protected void accept0(ASTVisitor visitor) {
boolean visitChildren = visitor.visit(this);
if (visitChildren) {
List<Parameter> parameters = getParameters();
for (Parameter parameter : parameters) {
acceptChild(visitor, parameter);
}
acceptChildren(visitor, getChildren());
}
visitor.endVisit(this);
}
use of com.redhat.qute.parser.template.Parameter in project quarkus-ls by redhat-developer.
the class EachSection method accept0.
@Override
protected void accept0(ASTVisitor visitor) {
boolean visitChildren = visitor.visit(this);
if (visitChildren) {
List<Parameter> parameters = getParameters();
for (Parameter parameter : parameters) {
acceptChild(visitor, parameter);
}
acceptChildren(visitor, getChildren());
}
visitor.endVisit(this);
}
use of com.redhat.qute.parser.template.Parameter in project quarkus-ls by redhat-developer.
the class ElseSection method accept0.
@Override
protected void accept0(ASTVisitor visitor) {
boolean visitChildren = visitor.visit(this);
if (visitChildren) {
List<Parameter> parameters = getParameters();
for (Parameter parameter : parameters) {
acceptChild(visitor, parameter);
}
acceptChildren(visitor, getChildren());
}
visitor.endVisit(this);
}
use of com.redhat.qute.parser.template.Parameter in project quarkus-ls by redhat-developer.
the class QuteCompletionsForExpression method doCompleteExpressionForObjectPartWithParentNodes.
private void doCompleteExpressionForObjectPartWithParentNodes(Node part, Node node, Range range, int offset, String projectUri, Set<String> existingVars, QuteCompletionSettings completionSettings, QuteFormattingSettings formattingSettings, CompletionList list) {
Section section = node != null ? node.getParentSection() : null;
if (section == null) {
return;
}
if (section.getKind() == NodeKind.Section) {
boolean collect = true;
if (section.getSectionKind() == SectionKind.FOR || section.getSectionKind() == SectionKind.EACH) {
LoopSection iterableSection = ((LoopSection) section);
if (iterableSection.isInElseBlock(offset)) {
// Completion is triggered after a #else inside a #for, we don't provide
// completion for metadata or aliases
collect = false;
}
}
if (collect) {
// 1) Completion for metadata section
List<SectionMetadata> metadatas = section.getMetadata();
for (SectionMetadata metadata : metadatas) {
String name = metadata.getName();
if (!existingVars.contains(name)) {
existingVars.add(name);
CompletionItem item = new CompletionItem();
item.setLabel(name);
item.setKind(CompletionItemKind.Keyword);
// Display metadata section (ex : count for #each) after declared objects
item.setSortText("Za" + name);
TextEdit textEdit = new TextEdit(range, name);
item.setTextEdit(Either.forLeft(textEdit));
item.setDetail(metadata.getDescription());
list.getItems().add(item);
}
}
// 2) Completion for aliases section
switch(section.getSectionKind()) {
case EACH:
case FOR:
LoopSection iterableSection = ((LoopSection) section);
// Completion for iterable section like #each, #for
String alias = iterableSection.getAlias();
if (!StringUtils.isEmpty(alias)) {
if (!existingVars.contains(alias)) {
existingVars.add(alias);
CompletionItem item = new CompletionItem();
item.setLabel(alias);
item.setKind(CompletionItemKind.Reference);
TextEdit textEdit = new TextEdit(range, alias);
item.setTextEdit(Either.forLeft(textEdit));
list.getItems().add(item);
}
}
break;
case LET:
case SET:
// completion for parameters coming from #let, #set
List<Parameter> parameters = section.getParameters();
if (parameters != null) {
for (Parameter parameter : parameters) {
String parameterName = parameter.getName();
if (!existingVars.contains(parameterName)) {
existingVars.add(parameterName);
CompletionItem item = new CompletionItem();
item.setLabel(parameterName);
item.setKind(CompletionItemKind.Reference);
TextEdit textEdit = new TextEdit(range, parameterName);
item.setTextEdit(Either.forLeft(textEdit));
list.getItems().add(item);
}
}
}
break;
case WITH:
// Completion for properties/methods of with object from #with
Parameter object = ((WithSection) section).getObjectParameter();
if (object != null) {
ResolvedJavaTypeInfo withJavaTypeInfo = javaCache.resolveJavaType(object, projectUri).getNow(null);
if (withJavaTypeInfo != null) {
fillCompletionFields(withJavaTypeInfo, range, projectUri, existingVars, list);
fillCompletionMethods(withJavaTypeInfo, range, projectUri, completionSettings, formattingSettings, existingVars, new HashSet<>(), list);
}
}
break;
default:
}
}
}
doCompleteExpressionForObjectPartWithParentNodes(part, section, range, offset, projectUri, existingVars, completionSettings, formattingSettings, list);
}
use of com.redhat.qute.parser.template.Parameter in project quarkus-ls by redhat-developer.
the class QutePositionUtility method findBestNode.
/**
* Find the best node from the given expression at the given offset.
*
* @param expression the expression node.
* @param offset the offset.
*
* @return the best node from the given expression at the given offset.
*/
private static Node findBestNode(Expression expression, int offset) {
Node expressionNode = expression.findNodeExpressionAt(offset);
if (expressionNode != null) {
if (expressionNode instanceof MethodPart) {
MethodPart method = (MethodPart) expressionNode;
Parameter parameter = method.getParameterAtOffset(offset);
if (parameter != null) {
Expression parameterExpression = parameter.getJavaTypeExpression();
if (parameterExpression != null) {
return findBestNode(parameterExpression, offset);
}
return parameter;
}
}
return expressionNode;
}
return expression;
}
Aggregations