void (@NotNull List<FoldingDescriptor> descriptors, @NotNull Collection<PsiElement> psiElements, @NotNull Document document) { Set<PsiElement> handledComments = new HashSet<>(); psiElements.forEach(element -> { if (element instanceof PsiComment && ((PsiComment)element).getTokenType() != ShTypes.SHEBANG && !handledComments.contains(element)) { PsiElement lastComment = element; PsiElement currentElement = element; handledComments.add(element); while (currentElement.getNextSibling() != null) { PsiElement nextSibling = currentElement.getNextSibling(); IElementType elementType = nextSibling.getNode().getElementType(); if (elementType != ShTypes.LINEFEED && elementType != ShTokenTypes.WHITESPACE && !(nextSibling instanceof PsiComment)) break; if (nextSibling instanceof PsiComment){ handledComments.add(nextSibling); lastComment = nextSibling; } currentElement = nextSibling; } if (element == lastComment) return; int startOffset = element.getTextRange().getStartOffset(); int endOffset = lastComment.getTextRange().getEndOffset(); descriptors.add(new FoldingDescriptor(element.getContainingFile().getNode(), TextRange.create(startOffset, endOffset), null, getCommentPlaceholder(element, document))); } }); }