PY-18928 fix multiline comments folding to handle custom folding regions correctly

This commit is contained in:
liana.bakradze
2016-03-25 19:29:53 +03:00
parent fde0e16923
commit 3a4c1d4575
4 changed files with 36 additions and 0 deletions
@@ -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
+7
View File
@@ -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();
}
}