use of com.redhat.qute.parser.template.Node 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.Node 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