use of com.intellij.lang.folding.FoldingDescriptor in project intellij by bazelbuild.
the class BuildFileFoldingBuilder method foldSequentialComments.
private static void foldSequentialComments(List<FoldingDescriptor> descriptors, ASTNode node) {
// need to skip previous comments in sequence
ASTNode curNode = node.getTreePrev();
while (curNode != null) {
if (curNode.getElementType() == BuildToken.COMMENT) {
return;
}
curNode = isWhitespaceOrNewline(curNode) ? curNode.getTreePrev() : null;
}
// fold sequence comments in one block
curNode = node.getTreeNext();
ASTNode lastCommentNode = node;
while (curNode != null) {
if (curNode.getElementType() == BuildToken.COMMENT) {
lastCommentNode = curNode;
curNode = curNode.getTreeNext();
continue;
}
curNode = isWhitespaceOrNewline(curNode) ? curNode.getTreeNext() : null;
}
if (lastCommentNode != node) {
descriptors.add(new FoldingDescriptor(node, TextRange.create(node.getStartOffset(), lastCommentNode.getTextRange().getEndOffset())));
}
}
use of com.intellij.lang.folding.FoldingDescriptor in project intellij by bazelbuild.
the class BuildFileFoldingBuilderTest method testMultilineCommentFolded.
@Test
public void testMultilineCommentFolded() throws Throwable {
BuildFile file = createBuildFile(new WorkspacePath("java/com/google/BUILD"), "# multi-line comment, folded", "# second line of comment", "def function(arg1, arg2):", " stmt1", " stmt2", "", "variable = 1");
FoldingDescriptor[] foldingRegions = getFoldingRegions(file);
assertThat(foldingRegions).hasLength(2);
assertThat(foldingRegions[0].getElement().getPsi()).isEqualTo(file.firstChildOfClass(PsiComment.class));
}
use of com.intellij.lang.folding.FoldingDescriptor in project intellij by bazelbuild.
the class BuildFileFoldingBuilderTest method testMultilineStringFoldedToFirstLine.
@Test
public void testMultilineStringFoldedToFirstLine() throws Throwable {
BuildFile file = createBuildFile(new WorkspacePath("java/com/google/BUILD"), "\"\"\"First line of string", "Second line of string\"\"\"");
FoldingDescriptor[] foldingRegions = getFoldingRegions(file);
assertThat(foldingRegions).hasLength(1);
assertThat(foldingRegions[0].getPlaceholderText()).isEqualTo("\"\"\"First line of string...\"\"\"");
}
use of com.intellij.lang.folding.FoldingDescriptor in project idea-php-typo3-plugin by cedricziel.
the class RouteFoldingBuilder method buildFoldRegions.
@NotNull
@Override
public FoldingDescriptor @NotNull [] buildFoldRegions(@NotNull PsiElement root, @NotNull Document document, boolean quick) {
FoldingGroup group = FoldingGroup.newGroup("TYPO3Route");
List<FoldingDescriptor> descriptors = new ArrayList<>();
Collection<StringLiteralExpression> literalExpressions = PsiTreeUtil.findChildrenOfType(root, StringLiteralExpression.class);
for (final StringLiteralExpression literalExpression : literalExpressions) {
for (PsiReference reference : literalExpression.getReferences()) {
if (reference instanceof RouteReference) {
String value = literalExpression.getContents();
FoldingDescriptor descriptor = foldRouteReferenceString(reference, value, group);
if (descriptor != null) {
descriptors.add(descriptor);
}
}
}
}
return descriptors.toArray(FoldingDescriptor.EMPTY);
}
use of com.intellij.lang.folding.FoldingDescriptor in project idea-php-typo3-plugin by cedricziel.
the class RouteFoldingBuilder method foldRouteReferenceString.
@Nullable
private FoldingDescriptor foldRouteReferenceString(PsiReference reference, String value, FoldingGroup group) {
PsiElement element = reference.getElement();
TextRange foldingRange = new TextRange(element.getTextRange().getStartOffset() + 1, element.getTextRange().getEndOffset() - 1);
if (!RouteIndex.hasRoute(element.getProject(), value)) {
return null;
}
Collection<RouteStub> route = RouteIndex.getRoute(element.getProject(), value);
if (route.size() == 0) {
return null;
}
RouteStub routeDef = route.iterator().next();
return new FoldingDescriptor(element.getNode(), foldingRange, group) {
@Nullable
@Override
public String getPlaceholderText() {
if (routeDef.getPath() == null) {
return routeDef.getController() + "::" + routeDef.getMethod();
}
return routeDef.getPath();
}
};
}
Aggregations