mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-18928 fix multiline comments folding to handle custom folding regions correctly
This commit is contained in:
@@ -90,10 +90,17 @@ public class PythonFoldingBuilder extends CustomFoldingBuilder implements DumbAw
|
||||
}
|
||||
|
||||
private static void foldSequentialComments(ASTNode node, List<FoldingDescriptor> descriptors) {
|
||||
//do not start folded comments from custom region
|
||||
if (isCustomRegionElement(node.getPsi())) {
|
||||
return;
|
||||
}
|
||||
//need to skip previous comments in sequence
|
||||
ASTNode curNode = node.getTreePrev();
|
||||
while (curNode != null) {
|
||||
if (curNode.getElementType() == PyTokenTypes.END_OF_LINE_COMMENT) {
|
||||
if (isCustomRegionElement(curNode.getPsi())) {
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
curNode = curNode.getPsi() instanceof PsiWhiteSpace ? curNode.getTreePrev() : null;
|
||||
@@ -104,6 +111,10 @@ public class PythonFoldingBuilder extends CustomFoldingBuilder implements DumbAw
|
||||
ASTNode lastCommentNode = node;
|
||||
while (curNode != null) {
|
||||
if (curNode.getElementType() == PyTokenTypes.END_OF_LINE_COMMENT) {
|
||||
//do not end folded comments with custom region
|
||||
if (isCustomRegionElement(curNode.getPsi())) {
|
||||
break;
|
||||
}
|
||||
lastCommentNode = curNode;
|
||||
curNode = curNode.getTreeNext();
|
||||
continue;
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
<fold text='Description'># region Description
|
||||
<fold text='...'># comment
|
||||
# comment</fold>
|
||||
print("test region")
|
||||
|
||||
<fold text='...'>## comment
|
||||
#comment</fold>
|
||||
# endregion</fold>
|
||||
# comment
|
||||
@@ -0,0 +1,7 @@
|
||||
<fold text='# Some description'># region # Some description
|
||||
<fold text='...'>## print("first line of commented code")
|
||||
## print("second line of commented code")
|
||||
# pass
|
||||
# # comment
|
||||
# pass</fold>
|
||||
# endregion # end of custom block</fold>
|
||||
@@ -57,4 +57,13 @@ public class PyFoldingTest extends PyTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testNestedFolding() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
//PY-18928
|
||||
public void testCustomFoldingWithComments() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user