From bfc761dff85314d61c5957c5397f30c210f7df1e Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Tue, 12 Nov 2013 14:41:26 +0100 Subject: [PATCH] allow wrapping in imports (PY-9163) --- python/src/com/jetbrains/python/formatter/PyBlock.java | 3 ++- python/testData/formatter/wrapImports.py | 1 + python/testData/formatter/wrapImports_after.py | 2 ++ python/testSrc/com/jetbrains/python/PyFormatterTest.java | 5 +++++ 4 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 python/testData/formatter/wrapImports.py create mode 100644 python/testData/formatter/wrapImports_after.py diff --git a/python/src/com/jetbrains/python/formatter/PyBlock.java b/python/src/com/jetbrains/python/formatter/PyBlock.java index 6d343e2f301d..c46601c85d27 100644 --- a/python/src/com/jetbrains/python/formatter/PyBlock.java +++ b/python/src/com/jetbrains/python/formatter/PyBlock.java @@ -146,7 +146,8 @@ public class PyBlock implements ASTBlock { childIndent = Indent.getNormalIndent(); } } - else if (childType == PyElementTypes.IMPORT_ELEMENT && hasLineBreaksBefore(child, 1)) { + else if (childType == PyElementTypes.IMPORT_ELEMENT) { + wrap = Wrap.createWrap(WrapType.NORMAL, true); childIndent = Indent.getNormalIndent(); } if (ourListElementTypes.contains(parentType)) { diff --git a/python/testData/formatter/wrapImports.py b/python/testData/formatter/wrapImports.py new file mode 100644 index 000000000000..e5ab6b46c69c --- /dev/null +++ b/python/testData/formatter/wrapImports.py @@ -0,0 +1 @@ +from common.resources.health import URLHealthCheck, JSONURLHealthCheck, HealthHandler, HealthResult \ No newline at end of file diff --git a/python/testData/formatter/wrapImports_after.py b/python/testData/formatter/wrapImports_after.py new file mode 100644 index 000000000000..7a58d05d70fe --- /dev/null +++ b/python/testData/formatter/wrapImports_after.py @@ -0,0 +1,2 @@ +from common.resources.health import URLHealthCheck, JSONURLHealthCheck, \ + HealthHandler, HealthResult \ 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 db623cf3b1eb..4b77c179a158 100644 --- a/python/testSrc/com/jetbrains/python/PyFormatterTest.java +++ b/python/testSrc/com/jetbrains/python/PyFormatterTest.java @@ -345,6 +345,11 @@ public class PyFormatterTest extends PyTestCase { doTest(); } + public void testWrapImports() { // PY-9163 + settings().RIGHT_MARGIN = 80; + doTest(); + } + private void doTest() { doTest(false); }