mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fixed a case when formatter breaks code (PY-4034 comment)
This commit is contained in:
@@ -177,7 +177,7 @@ public class PyBlock implements ASTBlock {
|
||||
childIndent = Indent.getNormalIndent();
|
||||
}
|
||||
}
|
||||
else if (parentType == PyElementTypes.PARENTHESIZED_EXPRESSION) {
|
||||
else if (parentType == PyElementTypes.PARENTHESIZED_EXPRESSION && hasLineBreaksBefore(child, 1)) {
|
||||
childIndent = Indent.getNormalIndent();
|
||||
}
|
||||
|
||||
@@ -242,7 +242,8 @@ public class PyBlock implements ASTBlock {
|
||||
}
|
||||
|
||||
private static boolean hasLineBreaksBefore(ASTNode child, int minCount) {
|
||||
return isWhitespaceWithLineBreaks(TreeUtil.findLastLeaf(child.getTreePrev()), minCount) ||
|
||||
final ASTNode treePrev = child.getTreePrev();
|
||||
return (treePrev != null && isWhitespaceWithLineBreaks(TreeUtil.findLastLeaf(treePrev), minCount)) ||
|
||||
isWhitespaceWithLineBreaks(child.getFirstChildNode(), minCount);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
def bad_autoformat_example():
|
||||
a = 5
|
||||
b = 10
|
||||
print a, b
|
||||
(a, b) = b, a
|
||||
print a, b
|
||||
a, b = b, a
|
||||
print a, b
|
||||
@@ -0,0 +1,8 @@
|
||||
def bad_autoformat_example():
|
||||
a = 5
|
||||
b = 10
|
||||
print a, b
|
||||
(a, b) = b, a
|
||||
print a, b
|
||||
a, b = b, a
|
||||
print a, b
|
||||
@@ -113,6 +113,10 @@ public class PyFormatterTest extends PyLightFixtureTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testTupleAssignment() { // PY-4034 comment
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testPsiFormatting() { // IDEA-69724
|
||||
String initial =
|
||||
"def method_name(\n" +
|
||||
|
||||
Reference in New Issue
Block a user