Added folding building for templates.
This commit is contained in:
@@ -6,10 +6,13 @@ import com.intellij.lang.folding.FoldingDescriptor;
|
|||||||
import com.intellij.openapi.editor.Document;
|
import com.intellij.openapi.editor.Document;
|
||||||
import com.intellij.openapi.project.DumbAware;
|
import com.intellij.openapi.project.DumbAware;
|
||||||
import com.intellij.openapi.util.TextRange;
|
import com.intellij.openapi.util.TextRange;
|
||||||
|
import com.intellij.psi.tree.IElementType;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.JetNodeTypes;
|
import org.jetbrains.jet.JetNodeTypes;
|
||||||
|
import org.jetbrains.jet.lexer.JetTokens;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -26,9 +29,14 @@ public class JetFoldingBuilder implements FoldingBuilder, DumbAware {
|
|||||||
|
|
||||||
private void appendDescriptors(ASTNode node, Document document, List<FoldingDescriptor> descriptors) {
|
private void appendDescriptors(ASTNode node, Document document, List<FoldingDescriptor> descriptors) {
|
||||||
TextRange textRange = node.getTextRange();
|
TextRange textRange = node.getTextRange();
|
||||||
if ((node.getElementType() == JetNodeTypes.BLOCK || node.getElementType() == JetNodeTypes.CLASS_BODY) &&
|
IElementType type = node.getElementType();
|
||||||
|
if ((type == JetNodeTypes.BLOCK || type == JetNodeTypes.CLASS_BODY) &&
|
||||||
!isOneLine(textRange, document)) {
|
!isOneLine(textRange, document)) {
|
||||||
descriptors.add(new FoldingDescriptor(node, textRange));
|
descriptors.add(new FoldingDescriptor(node, textRange));
|
||||||
|
} else if (type == JetNodeTypes.PARENTHESIZED && node.getFirstChildNode().getElementType() == JetTokens.IDE_TEMPLATE_START) {
|
||||||
|
if (node.getTreeParent().getTextLength() > 0) {
|
||||||
|
descriptors.add(new FoldingDescriptor(node, textRange, null, Collections.<Object>emptySet(), true));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ASTNode child = node.getFirstChildNode();
|
ASTNode child = node.getFirstChildNode();
|
||||||
while (child != null) {
|
while (child != null) {
|
||||||
@@ -37,12 +45,16 @@ public class JetFoldingBuilder implements FoldingBuilder, DumbAware {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isOneLine(TextRange textRange, Document document) {
|
private static boolean isOneLine(TextRange textRange, Document document) {
|
||||||
return document.getLineNumber(textRange.getStartOffset()) == document.getLineNumber(textRange.getEndOffset());
|
return document.getLineNumber(textRange.getStartOffset()) == document.getLineNumber(textRange.getEndOffset());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPlaceholderText(@NotNull ASTNode astNode) {
|
public String getPlaceholderText(@NotNull ASTNode astNode) {
|
||||||
|
if (astNode.getElementType() == JetNodeTypes.PARENTHESIZED && astNode.getFirstChildNode().getElementType() == JetTokens.IDE_TEMPLATE_START) {
|
||||||
|
ASTNode placeholderExpression = astNode.getFirstChildNode().getTreeNext();
|
||||||
|
return placeholderExpression.getText();
|
||||||
|
}
|
||||||
return "{...}";
|
return "{...}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user