diff --git a/python/src/com/jetbrains/python/formatter/PyBlock.java b/python/src/com/jetbrains/python/formatter/PyBlock.java index 86244e6c45a9..45d2bcedfb06 100644 --- a/python/src/com/jetbrains/python/formatter/PyBlock.java +++ b/python/src/com/jetbrains/python/formatter/PyBlock.java @@ -162,7 +162,7 @@ public class PyBlock implements ASTBlock { childIndent = Indent.getNoneIndent(); } else { - childIndent = parentType == PyElementTypes.PARAMETER_LIST + childIndent = parentType == PyElementTypes.PARAMETER_LIST || isCallInControlStatement() ? Indent.getContinuationIndent() : Indent.getNormalIndent(); } @@ -214,6 +214,10 @@ public class PyBlock implements ASTBlock { return new PyBlock(this, child, childAlignment, childIndent, wrap, myContext); } + private boolean isCallInControlStatement() { + return PsiTreeUtil.getParentOfType(_node.getPsi(), PyStatementPart.class, false, PyStatementList.class) != null; + } + private boolean isSliceOperand(ASTNode child) { if (_node.getPsi() instanceof PySliceExpression) { PySliceExpression sliceExpression = (PySliceExpression)_node.getPsi(); diff --git a/python/testData/formatter/continuationIndentForCallInStatementPart.py b/python/testData/formatter/continuationIndentForCallInStatementPart.py new file mode 100644 index 000000000000..a8af12613683 --- /dev/null +++ b/python/testData/formatter/continuationIndentForCallInStatementPart.py @@ -0,0 +1,3 @@ +for item in really_long_name_of_the_function_with_a_lot_of_patams( + param1, param2, param3): + pass \ No newline at end of file diff --git a/python/testData/formatter/continuationIndentForCallInStatementPart_after.py b/python/testData/formatter/continuationIndentForCallInStatementPart_after.py new file mode 100644 index 000000000000..cef6a8a4fd54 --- /dev/null +++ b/python/testData/formatter/continuationIndentForCallInStatementPart_after.py @@ -0,0 +1,3 @@ +for item in really_long_name_of_the_function_with_a_lot_of_patams( + param1, param2, param3): + pass \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/PyFormatterTest.java b/python/testSrc/com/jetbrains/python/PyFormatterTest.java index 15fc7db0a4df..b56aa6006e8a 100644 --- a/python/testSrc/com/jetbrains/python/PyFormatterTest.java +++ b/python/testSrc/com/jetbrains/python/PyFormatterTest.java @@ -255,6 +255,10 @@ public class PyFormatterTest extends PyTestCase { doTest(); } + public void testContinuationIndentForCallInStatementPart() { // PY-8577 + doTest(); + } + private void doTest() { myFixture.configureByFile("formatter/" + getTestName(true) + ".py"); ApplicationManager.getApplication().runWriteAction(new Runnable() {