mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Remove formatter logic that prevented proper alignment of empty collection literals
It was added a while back for PY-6751, but corresponding test passes without it now. Also it turned out that PyIndentTest#testEnterInDictInTuple depended on this change, but behavior tested there was recreated (once again) by proper use of hasHangingIndent in formatter, i.e. once opening and closing braces of the dict are on different lines, the literal should not have alignment.
This commit is contained in:
@@ -514,14 +514,9 @@ public class PyBlock implements ASTBlock {
|
||||
|
||||
private boolean needListAlignment(ASTNode child) {
|
||||
final IElementType childType = child.getElementType();
|
||||
final ASTNode firstGrandchild = child.getFirstChildNode();
|
||||
final IElementType firstGrandchildType = firstGrandchild == null ? null : firstGrandchild.getElementType();
|
||||
if (PyTokenTypes.OPEN_BRACES.contains(childType)) {
|
||||
return false;
|
||||
}
|
||||
if (PyTokenTypes.OPEN_BRACES.contains(firstGrandchildType) && isEmptySequence(child)) {
|
||||
return false;
|
||||
}
|
||||
if (PyTokenTypes.CLOSE_BRACES.contains(childType)) {
|
||||
final ASTNode prevNonSpace = findPrevNonSpaceNode(child);
|
||||
if (prevNonSpace != null &&
|
||||
@@ -549,7 +544,7 @@ public class PyBlock implements ASTBlock {
|
||||
if (child.getElementType() == PyTokenTypes.COMMA) {
|
||||
return false;
|
||||
}
|
||||
return myContext.getPySettings().ALIGN_COLLECTIONS_AND_COMPREHENSIONS;
|
||||
return myContext.getPySettings().ALIGN_COLLECTIONS_AND_COMPREHENSIONS && !hasHangingIndent(myNode.getPsi());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
xs = [(),
|
||||
42]
|
||||
@@ -0,0 +1,2 @@
|
||||
xs = [(),
|
||||
42]
|
||||
@@ -0,0 +1,4 @@
|
||||
xs = [[],
|
||||
{},
|
||||
(),
|
||||
42]
|
||||
@@ -0,0 +1,4 @@
|
||||
xs = [[],
|
||||
{},
|
||||
(),
|
||||
42]
|
||||
@@ -546,6 +546,10 @@ public class PyFormatterTest extends PyTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testAlignmentInListLiteralWhereFirstItemIsEmptyTuple() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testHangingIndentInNamedArgumentValue() {
|
||||
doTest();
|
||||
}
|
||||
@@ -554,6 +558,10 @@ public class PyFormatterTest extends PyTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testAlignmentOfEmptyCollectionLiterals() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private CommonCodeStyleSettings getCommonSettings() {
|
||||
return settings().getCommonSettings(PythonLanguage.getInstance());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user