From b523566c4eaacb9b8d9982512ad81c4e2a33eeb3 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Wed, 15 Aug 2012 12:04:12 +0200 Subject: [PATCH] fix alignment after first argument in call (PY-6360) --- .../src/com/jetbrains/python/psi/impl/PyPsiUtils.java | 2 +- python/src/com/jetbrains/python/formatter/PyBlock.java | 7 ++++++- python/testSrc/com/jetbrains/python/PyIndentTest.java | 8 ++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/python/psi-api/src/com/jetbrains/python/psi/impl/PyPsiUtils.java b/python/psi-api/src/com/jetbrains/python/psi/impl/PyPsiUtils.java index 88d691436fd2..2cc39b19ce07 100644 --- a/python/psi-api/src/com/jetbrains/python/psi/impl/PyPsiUtils.java +++ b/python/psi-api/src/com/jetbrains/python/psi/impl/PyPsiUtils.java @@ -55,7 +55,7 @@ public class PyPsiUtils { } @Nullable - protected static ASTNode getNextComma(ASTNode after) { + public static ASTNode getNextComma(ASTNode after) { ASTNode node = after; PyElementType comma = PyTokenTypes.COMMA; do { diff --git a/python/src/com/jetbrains/python/formatter/PyBlock.java b/python/src/com/jetbrains/python/formatter/PyBlock.java index 2e6744297aaa..dc6956d7691f 100644 --- a/python/src/com/jetbrains/python/formatter/PyBlock.java +++ b/python/src/com/jetbrains/python/formatter/PyBlock.java @@ -15,6 +15,7 @@ import com.jetbrains.python.PyElementTypes; import com.jetbrains.python.PyTokenTypes; import com.jetbrains.python.PythonDialectsTokenSetProvider; import com.jetbrains.python.psi.*; +import com.jetbrains.python.psi.impl.PyPsiUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -238,7 +239,11 @@ public class PyBlock implements ASTBlock { return false; } PyArgumentList argList = (PyArgumentList)_node.getPsi(); - return argList != null && argList.getArguments().length > 1; + if (argList != null) { + PyExpression[] arguments = argList.getArguments(); + return arguments.length > 1 || (arguments.length == 1 && PyPsiUtils.getNextComma(arguments[0].getNode()) != null); + } + return false; } if (_node.getElementType() == PyElementTypes.PARAMETER_LIST) { return mySettings.ALIGN_MULTILINE_PARAMETERS; diff --git a/python/testSrc/com/jetbrains/python/PyIndentTest.java b/python/testSrc/com/jetbrains/python/PyIndentTest.java index 4dd8188a760e..c4149825d674 100644 --- a/python/testSrc/com/jetbrains/python/PyIndentTest.java +++ b/python/testSrc/com/jetbrains/python/PyIndentTest.java @@ -2,6 +2,7 @@ package com.jetbrains.python; import com.intellij.openapi.actionSystem.IdeActions; import com.intellij.openapi.command.CommandProcessor; +import com.intellij.psi.codeStyle.CodeStyleSettingsManager; import com.jetbrains.python.fixtures.PyTestCase; /** @@ -295,6 +296,13 @@ public class PyIndentTest extends PyTestCase { "]"); } + public void testAlignInCall() { // PY-6360 + CodeStyleSettingsManager.getInstance().getSettings(myFixture.getProject()).ALIGN_MULTILINE_PARAMETERS_IN_CALLS = true; + doTest("list(a,)", + "list(a,\n" + + " )"); + } + /* TODO: formatter core problem? public void testAlignListBeforeEquals() throws Exception {