From 9e5e7b3169c97ee0e5310a37d3189c83cefa778d Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Tue, 17 May 2011 17:57:30 +0200 Subject: [PATCH] several more cases of inconsistent indentation (PY-1947) --- .../jetbrains/python/formatter/PyBlock.java | 8 +++++--- .../com/jetbrains/python/PyIndentTest.java | 20 +++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/python/src/com/jetbrains/python/formatter/PyBlock.java b/python/src/com/jetbrains/python/formatter/PyBlock.java index 10e355f9abb4..82d77decb709 100644 --- a/python/src/com/jetbrains/python/formatter/PyBlock.java +++ b/python/src/com/jetbrains/python/formatter/PyBlock.java @@ -141,7 +141,7 @@ public class PyBlock implements ASTBlock { childIndent = Indent.getNoneIndent(); } else { - childIndent = Indent.getContinuationIndent(); + childIndent = Indent.getNormalIndent(); } } else if (parentType == PyElementTypes.ARGUMENT_LIST) { @@ -152,7 +152,7 @@ public class PyBlock implements ASTBlock { childIndent = Indent.getNormalIndent(); } } - else if (parentType == PyElementTypes.DICT_LITERAL_EXPRESSION) { + else if (parentType == PyElementTypes.DICT_LITERAL_EXPRESSION || parentType == PyElementTypes.SET_LITERAL_EXPRESSION) { if (childType == PyTokenTypes.RBRACE) { childIndent = Indent.getNoneIndent(); } @@ -211,7 +211,9 @@ public class PyBlock implements ASTBlock { private boolean needListAlignment(ASTNode child) { IElementType childType = child.getElementType(); - if (PyTokenTypes.OPEN_BRACES.contains(childType)) { + ASTNode firstGrandchild = child.getFirstChildNode(); + IElementType firstGrandchildType = firstGrandchild == null ? null : firstGrandchild.getElementType(); + if (PyTokenTypes.OPEN_BRACES.contains(childType) || PyTokenTypes.OPEN_BRACES.contains(firstGrandchildType)) { return false; } if (PyTokenTypes.CLOSE_BRACES.contains(childType)) { diff --git a/python/testSrc/com/jetbrains/python/PyIndentTest.java b/python/testSrc/com/jetbrains/python/PyIndentTest.java index 5cd39c0783d6..e79dcba68aae 100644 --- a/python/testSrc/com/jetbrains/python/PyIndentTest.java +++ b/python/testSrc/com/jetbrains/python/PyIndentTest.java @@ -192,6 +192,26 @@ public class PyIndentTest extends PyLightFixtureTestCase { " params=1)"); } + public void testEnterInSet() { // PY-1947 + doTest("test_set = {'some_value'}", + "test_set = {\n" + + " 'some_value'}"); + + } + + public void testEnterInList() { // PY-1947 + doTest("test_list = ['some_value']", + "test_list = [\n" + + " 'some_value']"); + } + + public void testEnterInDictInTuple() { // PY-1947 + doTest("td = ({})", + "td = ({\n" + + " \n" + + "})"); + } + public void testIndentAfterComment() { // PY-641 doTest("def foo():\n #some_call()\n another_call()", "def foo():\n #some_call()\n \n another_call()"); }