use of com.redhat.qute.parser.template.Section in project quarkus-ls by redhat-developer.
the class QuteProject method collectInsert.
private void collectInsert(String insertParamater, Node parent, Template template, List<QuteIndex> indexes) {
if (parent.getKind() == NodeKind.Section) {
Section section = (Section) parent;
if (section.getSectionKind() == SectionKind.INSERT) {
Parameter parameter = section.getParameterAtIndex(0);
if (parameter != null) {
try {
if (insertParamater == null || insertParamater.equals(parameter.getValue())) {
Position position = template.positionAt(parameter.getStart());
Path path = createPath(template.getUri());
QuteTemplateIndex templateIndex = new QuteTemplateIndex(path, template.getTemplateId());
QuteIndex index = new QuteIndex("insert", parameter.getValue(), position, SectionKind.INSERT, templateIndex);
indexes.add(index);
}
} catch (BadLocationException e) {
e.printStackTrace();
}
}
}
}
List<Node> children = parent.getChildren();
for (Node node : children) {
collectInsert(insertParamater, node, template, indexes);
}
}
use of com.redhat.qute.parser.template.Section in project quarkus-ls by redhat-developer.
the class QuteCodeActions method doCodeActionsForUndefinedSectionTag.
private static void doCodeActionsForUndefinedSectionTag(Template template, Diagnostic diagnostic, List<CodeAction> codeActions) {
QuteProject project = template.getProject();
if (project == null) {
return;
}
try {
String tagName = null;
JsonObject data = (JsonObject) diagnostic.getData();
if (data != null) {
tagName = data.get(DIAGNOSTIC_DATA_TAG).getAsString();
} else {
int offset = template.offsetAt(diagnostic.getRange().getStart());
Node node = template.findNodeAt(offset);
node = QutePositionUtility.findBestNode(offset, node);
if (node.getKind() == NodeKind.Section) {
Section section = (Section) node;
tagName = section.getTag();
}
}
if (tagName == null) {
return;
}
// TODO : use a settings to know the preferred file extension
String preferedFileExtension = ".html";
String tagFileUri = project.getTagsDir().resolve(tagName + preferedFileExtension).toUri().toString();
String title = MessageFormat.format(UNDEFINED_SECTION_TAG_CODEACTION_TITLE, tagName);
CodeAction createUserTagFile = CodeActionFactory.createFile(title, tagFileUri, "", diagnostic);
codeActions.add(createUserTagFile);
} catch (BadLocationException e) {
LOGGER.log(Level.SEVERE, "Creation of undefined user tag code action failed", e);
}
}
use of com.redhat.qute.parser.template.Section in project quarkus-ls by redhat-developer.
the class Part method getParentSection.
@Override
public Section getParentSection() {
Parts parts = getParent();
Expression expression = parts.getParent();
Node parent = expression.getParent();
if (parent.getKind() == NodeKind.Parameter) {
// Its' a parameter which belongs to a section (ex : items):
// {#for item in items}
// In this case we must get the parent of the parameter section
Node ownerSection = parent.getParent();
parent = ownerSection.getParent();
}
// loop for parent node to retrieve the parent section.
while (parent != null) {
if (parent.getKind() == NodeKind.Section) {
return (Section) parent;
}
parent = parent.getParent();
}
return null;
}
Aggregations