honor space after comma option in formatter (PY-486)

This commit is contained in:
Dmitry Jemerov
2010-03-17 15:37:10 +03:00
parent 1cedc23891
commit b0ddfa2c05
4 changed files with 15 additions and 0 deletions
@@ -215,6 +215,10 @@ public class PyBlock implements ASTBlock {
if (type1 == PyTokenTypes.COLON && type2 == PyElementTypes.STATEMENT_LIST) {
return Spacing.createSpacing(1, Integer.MAX_VALUE, 0, true, 0);
}
if (type1 == PyTokenTypes.COMMA) {
return getSpacingForOption(mySettings.SPACE_AFTER_COMMA);
}
/*
if (type1 == PyTokenTypes.COLON && type2 == PyElementTypes.STATEMENT_LIST) {
return Spacing.createSpacing(0, Integer.MAX_VALUE, 1, true, Integer.MAX_VALUE);
@@ -239,6 +243,11 @@ public class PyBlock implements ASTBlock {
return null;
}
private Spacing getSpacingForOption(boolean isOptionSet) {
int spaces = isOptionSet ? 1 : 0;
return Spacing.createSpacing(spaces, spaces, 0, mySettings.KEEP_LINE_BREAKS, mySettings.KEEP_BLANK_LINES_IN_CODE);
}
private static boolean isStatementOrDeclaration(final IElementType type) {
return PyElementTypes.STATEMENTS.contains(type) ||
type == PyElementTypes.CLASS_DECLARATION ||
@@ -0,0 +1 @@
import os,sys
@@ -0,0 +1 @@
import os, sys
@@ -16,6 +16,10 @@ public class PyFormatterTest extends PyLightFixtureTestCase {
doTest();
}
public void testSpaceAfterComma() throws Exception {
doTest();
}
private void doTest() throws Exception {
myFixture.configureByFile("formatter/" + getTestName(true) + ".py");
ApplicationManager.getApplication().runWriteAction(new Runnable() {