From a2465ccf2266d57358f8e7e729ebc246260ec5b7 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Wed, 18 May 2011 14:19:04 +0200 Subject: [PATCH] tweak logic for detecting incomplete formatter blocks (PY-3572) --- .../com/jetbrains/python/formatter/PyBlock.java | 9 +++++++++ .../com/jetbrains/python/PyIndentTest.java | 16 ++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/python/src/com/jetbrains/python/formatter/PyBlock.java b/python/src/com/jetbrains/python/formatter/PyBlock.java index 82d77decb709..217eb1c47456 100644 --- a/python/src/com/jetbrains/python/formatter/PyBlock.java +++ b/python/src/com/jetbrains/python/formatter/PyBlock.java @@ -670,6 +670,15 @@ public class PyBlock implements ASTBlock { } public boolean isIncomplete() { + // if there's something following us, we're not incomplete + PsiElement element = _node.getPsi().getNextSibling(); + while (element instanceof PsiWhiteSpace) { + element = element.getNextSibling(); + } + if (element != null) { + return false; + } + ASTNode lastChild = getLastNonSpaceChild(_node, false); if (lastChild != null && lastChild.getElementType() == PyElementTypes.STATEMENT_LIST) { // only multiline statement lists are considered incomplete diff --git a/python/testSrc/com/jetbrains/python/PyIndentTest.java b/python/testSrc/com/jetbrains/python/PyIndentTest.java index e79dcba68aae..6b558d602b40 100644 --- a/python/testSrc/com/jetbrains/python/PyIndentTest.java +++ b/python/testSrc/com/jetbrains/python/PyIndentTest.java @@ -249,6 +249,22 @@ public class PyIndentTest extends PyLightFixtureTestCase { " \n"); } + public void testIndentAfterModuleLevelStatement() { // PY-3572 + doTest("def a(var):\n" + + " if var == 'default':\n" + + " pass\n" + + "\n" + + "b = 1\n" + + "", + "def a(var):\n" + + " if var == 'default':\n" + + " pass\n" + + "\n" + + "b = 1\n" + + "\n" + + ""); + } + /* TODO: formatter core problem? public void testAlignListBeforeEquals() throws Exception {