Custom Language Plugin: Folding one range folds all ranges


I've implemented FoldingBuilder from the custom language plugin tutorial.  I've used a different logic, but the data structures returned are the same.

The folding ranges displayed are correct, but when I (un)fold one of the ranges, all the ranges (un)fold.

Are you able to pinpoint what could be wrong here?


Sorry, here is my code:

public FoldingDescriptor @NotNull [] buildFoldRegions(@NotNull PsiElement root, @NotNull Document document, boolean quick) {
FoldingGroup group = FoldingGroup.newGroup(someName);
List<FoldingDescriptor> descriptors = new ArrayList<FoldingDescriptor>();
PsiElement element = getNext2(root.getFirstChild());
while (element != null) {
PsiElement start = getNext1(element);
PsiElement end = getNext2(start); // might be null = end of file
if (start != null) {
TextRange range = getBlockRange(start, end);
if (range != null)
descriptors.add(new FoldingDescriptor(start.getNode(), range, group));
element = end;
return descriptors.toArray(new FoldingDescriptor[descriptors.size()]);

Do they have to be different groups?  The tutorial used only one group, though.


Yes, I do have to use different FoldingGroups ...


from Javadoc

> * {@link com.intellij.openapi.editor.FoldRegion}s with same FoldingGroup instances expand and collapse together.


Please sign in to leave a comment.