nicer formatting for dict literals (PY-1461)

This commit is contained in:
Dmitry Jemerov
2010-07-28 16:17:20 +04:00
parent 675ae89423
commit ed916ba850
4 changed files with 27 additions and 1 deletions

View File

@@ -116,7 +116,7 @@ public class PyBlock implements ASTBlock {
}
if (ourListElementTypes.contains(parentType)) {
wrap = Wrap.createWrap(WrapType.NORMAL, true);
if (!PyTokenTypes.OPEN_BRACES.contains(childType)) {
if (!PyTokenTypes.OPEN_BRACES.contains(childType) && !PyTokenTypes.CLOSE_BRACES.contains(childType)) {
childAlignment = _childListAlignment;
}
}
@@ -136,6 +136,14 @@ public class PyBlock implements ASTBlock {
childIndent = Indent.getContinuationIndent();
}
}
else if (parentType == PyElementTypes.DICT_LITERAL_EXPRESSION) {
if (childType == PyTokenTypes.RBRACE) {
childIndent = Indent.getNoneIndent();
}
else {
childIndent = Indent.getNormalIndent();
}
}
try { // maybe enter was pressed and cut us from a previous (nested) statement list
PsiElement prev = sure(child.getPsi().getPrevSibling());
sure(prev instanceof PyStatement);

View File

@@ -0,0 +1,7 @@
map = {
'node': {
'key1': 'key1value',
'key2': 'key2value',
'key3': 'key3value'
}
}

View File

@@ -0,0 +1,7 @@
map = {
'node': {
'key1': 'key1value',
'key2': 'key2value',
'key3': 'key3value'
}
}

View File

@@ -48,6 +48,10 @@ public class PyFormatterTest extends PyLightFixtureTestCase {
doTest();
}
public void testDictLiteral() { // PY-1461
doTest();
}
private void doTest() {
myFixture.configureByFile("formatter/" + getTestName(true) + ".py");
ApplicationManager.getApplication().runWriteAction(new Runnable() {