From b0ddfa2c05945f83f18b8c395625a162bdb6043e Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Tue, 16 Mar 2010 20:57:34 +0300 Subject: [PATCH] honor space after comma option in formatter (PY-486) --- python/src/com/jetbrains/python/formatter/PyBlock.java | 9 +++++++++ python/testData/formatter/spaceAfterComma.py | 1 + python/testData/formatter/spaceAfterComma_after.py | 1 + python/testSrc/com/jetbrains/python/PyFormatterTest.java | 4 ++++ 4 files changed, 15 insertions(+) create mode 100644 python/testData/formatter/spaceAfterComma.py create mode 100644 python/testData/formatter/spaceAfterComma_after.py diff --git a/python/src/com/jetbrains/python/formatter/PyBlock.java b/python/src/com/jetbrains/python/formatter/PyBlock.java index d47e30ddab38..d94d2bfe4c55 100644 --- a/python/src/com/jetbrains/python/formatter/PyBlock.java +++ b/python/src/com/jetbrains/python/formatter/PyBlock.java @@ -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 || diff --git a/python/testData/formatter/spaceAfterComma.py b/python/testData/formatter/spaceAfterComma.py new file mode 100644 index 000000000000..5e80f96ff8f3 --- /dev/null +++ b/python/testData/formatter/spaceAfterComma.py @@ -0,0 +1 @@ +import os,sys \ No newline at end of file diff --git a/python/testData/formatter/spaceAfterComma_after.py b/python/testData/formatter/spaceAfterComma_after.py new file mode 100644 index 000000000000..c38e1a2ed221 --- /dev/null +++ b/python/testData/formatter/spaceAfterComma_after.py @@ -0,0 +1 @@ +import os, sys \ 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 d452abd0a704..d80e5f00710d 100644 --- a/python/testSrc/com/jetbrains/python/PyFormatterTest.java +++ b/python/testSrc/com/jetbrains/python/PyFormatterTest.java @@ -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() {