From 035efc6bba3c166b12f47288807240dd6fad30b3 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Mon, 28 Jan 2013 16:37:02 +0100 Subject: [PATCH] indent, rather than align, child expression of subscription expression (PY-8572) --- python/src/com/jetbrains/python/formatter/PyBlock.java | 9 +++++++++ python/testData/formatter/indentInSlice.py | 4 ++++ python/testData/formatter/indentInSlice_after.py | 5 +++++ python/testSrc/com/jetbrains/python/PyFormatterTest.java | 8 +++++++- 4 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 python/testData/formatter/indentInSlice.py create mode 100644 python/testData/formatter/indentInSlice_after.py diff --git a/python/src/com/jetbrains/python/formatter/PyBlock.java b/python/src/com/jetbrains/python/formatter/PyBlock.java index ade68eece4aa..86244e6c45a9 100644 --- a/python/src/com/jetbrains/python/formatter/PyBlock.java +++ b/python/src/com/jetbrains/python/formatter/PyBlock.java @@ -200,6 +200,12 @@ public class PyBlock implements ASTBlock { childIndent = Indent.getNormalIndent(); } } + else if (parentType == PyElementTypes.SUBSCRIPTION_EXPRESSION) { + PyExpression indexExpression = ((PySubscriptionExpression)_node.getPsi()).getIndexExpression(); + if (indexExpression != null && child == indexExpression.getNode()) { + childIndent = Indent.getNormalIndent(); + } + } if (isAfterStatementList(child) && !hasLineBreaksBefore(child, 2)) { // maybe enter was pressed and cut us from a previous (nested) statement list childIndent = Indent.getNormalIndent(); @@ -279,6 +285,9 @@ public class PyBlock implements ASTBlock { if (_node.getElementType() == PyElementTypes.PARAMETER_LIST) { return myContext.getSettings().ALIGN_MULTILINE_PARAMETERS; } + if (_node.getElementType() == PyElementTypes.SUBSCRIPTION_EXPRESSION) { + return false; + } if (child.getElementType() == PyTokenTypes.COMMA) { return false; } diff --git a/python/testData/formatter/indentInSlice.py b/python/testData/formatter/indentInSlice.py new file mode 100644 index 000000000000..df1fd2193c18 --- /dev/null +++ b/python/testData/formatter/indentInSlice.py @@ -0,0 +1,4 @@ +if True: + if False: + if True: + returnData['error_text'] = "User with " + email_address + " email address is already part of " + company.name \ No newline at end of file diff --git a/python/testData/formatter/indentInSlice_after.py b/python/testData/formatter/indentInSlice_after.py new file mode 100644 index 000000000000..138bb872c96d --- /dev/null +++ b/python/testData/formatter/indentInSlice_after.py @@ -0,0 +1,5 @@ +if True: + if False: + if True: + returnData[ + 'error_text'] = "User with " + email_address + " email address is already part of " + company.name \ 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 1ed4401df735..15fc7db0a4df 100644 --- a/python/testSrc/com/jetbrains/python/PyFormatterTest.java +++ b/python/testSrc/com/jetbrains/python/PyFormatterTest.java @@ -248,7 +248,13 @@ public class PyFormatterTest extends PyTestCase { settings().WRAP_LONG_LINES = false; doTest(); } - + + public void testIndentInSlice() { // PY-8572 + settings().RIGHT_MARGIN = 120; + settings().WRAP_LONG_LINES = false; + doTest(); + } + private void doTest() { myFixture.configureByFile("formatter/" + getTestName(true) + ".py"); ApplicationManager.getApplication().runWriteAction(new Runnable() {