use of com.dmarcotte.handlebars.psi.HbBlockWrapper in project intellij-plugins by JetBrains.
the class HbFoldingBuilder method appendDescriptors.
private void appendDescriptors(PsiElement psi, List<FoldingDescriptor> descriptors, Document document) {
if (isSingleLine(psi, document)) {
return;
}
if (HbTokenTypes.COMMENT == psi.getNode().getElementType()) {
ASTNode commentNode = psi.getNode();
String commentText = commentNode.getText();
// tags before we allow folding
if (commentText.length() > 6 && commentText.substring(0, 3).equals("{{!") && commentText.substring(commentText.length() - 2, commentText.length()).equals("}}")) {
TextRange range = new TextRange(commentNode.getTextRange().getStartOffset() + 3, commentNode.getTextRange().getEndOffset() - 2);
descriptors.add(new FoldingDescriptor(commentNode, range));
}
}
if (psi instanceof HbBlockWrapper) {
PsiElement endOpenBlockStache = getOpenBlockCloseStacheElement(psi.getFirstChild());
PsiElement endCloseBlockStache = getCloseBlockCloseStacheElement(psi.getLastChild());
// if we've got a well formed block with the open and close elems we need, define a region to fold
if (endOpenBlockStache != null && endCloseBlockStache != null) {
int endOfFirstOpenStacheLine = document.getLineEndOffset(document.getLineNumber(psi.getTextRange().getStartOffset()));
// we set the start of the text we'll fold to be just before the close braces of the open stache,
// or, if the open stache spans multiple lines, to the end of the first line
int foldingRangeStartOffset = Math.min(endOpenBlockStache.getTextRange().getStartOffset(), endOfFirstOpenStacheLine);
// we set the end of the text we'll fold to be just before the final close braces in this block
int foldingRangeEndOffset = endCloseBlockStache.getTextRange().getStartOffset();
TextRange range = new TextRange(foldingRangeStartOffset, foldingRangeEndOffset);
descriptors.add(new FoldingDescriptor(psi, range));
}
}
PsiElement child = psi.getFirstChild();
while (child != null) {
appendDescriptors(child, descriptors, document);
child = child.getNextSibling();
}
}
use of com.dmarcotte.handlebars.psi.HbBlockWrapper in project idea-handlebars by dmarcotte.
the class HbFoldingBuilder method appendDescriptors.
private void appendDescriptors(PsiElement psi, List<FoldingDescriptor> descriptors, Document document) {
if (isSingleLine(psi, document)) {
return;
}
if (HbTokenTypes.COMMENT == psi.getNode().getElementType()) {
ASTNode commentNode = psi.getNode();
String commentText = commentNode.getText();
// tags before we allow folding
if (commentText.length() > 6 && commentText.substring(0, 3).equals("{{!") && commentText.substring(commentText.length() - 2, commentText.length()).equals("}}")) {
TextRange range = new TextRange(commentNode.getTextRange().getStartOffset() + 3, commentNode.getTextRange().getEndOffset() - 2);
descriptors.add(new FoldingDescriptor(commentNode, range));
}
}
if (psi instanceof HbBlockWrapper) {
PsiElement endOpenBlockStache = getOpenBlockCloseStacheElement(psi.getFirstChild());
PsiElement endCloseBlockStache = getCloseBlockCloseStacheElement(psi.getLastChild());
// if we've got a well formed block with the open and close elems we need, define a region to fold
if (endOpenBlockStache != null && endCloseBlockStache != null) {
int endOfFirstOpenStacheLine = document.getLineEndOffset(document.getLineNumber(psi.getTextRange().getStartOffset()));
// we set the start of the text we'll fold to be just before the close braces of the open stache,
// or, if the open stache spans multiple lines, to the end of the first line
int foldingRangeStartOffset = Math.min(endOpenBlockStache.getTextRange().getStartOffset(), endOfFirstOpenStacheLine);
// we set the end of the text we'll fold to be just before the final close braces in this block
int foldingRangeEndOffset = endCloseBlockStache.getTextRange().getStartOffset();
TextRange range = new TextRange(foldingRangeStartOffset, foldingRangeEndOffset);
descriptors.add(new FoldingDescriptor(psi, range));
}
}
PsiElement child = psi.getFirstChild();
while (child != null) {
appendDescriptors(child, descriptors, document);
child = child.getNextSibling();
}
}
Aggregations