use of com.redhat.qute.parser.template.sections.WithSection 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);
}
Aggregations