diff --git a/python/src/com/jetbrains/python/codeInsight/editorActions/smartEnter/fixers/PyParameterListFixer.java b/python/src/com/jetbrains/python/codeInsight/editorActions/smartEnter/fixers/PyParameterListFixer.java index 6b39d1eca739..e4359a43c640 100644 --- a/python/src/com/jetbrains/python/codeInsight/editorActions/smartEnter/fixers/PyParameterListFixer.java +++ b/python/src/com/jetbrains/python/codeInsight/editorActions/smartEnter/fixers/PyParameterListFixer.java @@ -40,19 +40,22 @@ public class PyParameterListFixer extends PyFixer { } @Override - public void doApply(@NotNull Editor editor, @NotNull PySmartEnterProcessor processor, @NotNull PyParameterList psiElement) + public void doApply(@NotNull Editor editor, @NotNull PySmartEnterProcessor processor, @NotNull PyParameterList parameters) throws IncorrectOperationException { - final PsiElement lBrace = PyUtil.getChildByFilter(psiElement, PyTokenTypes.OPEN_BRACES, 0); - final PsiElement rBrace = PyUtil.getChildByFilter(psiElement, PyTokenTypes.CLOSE_BRACES, 0); - final PyFunction pyFunction = as(psiElement.getParent(), PyFunction.class); + final PsiElement lBrace = PyUtil.getChildByFilter(parameters, PyTokenTypes.OPEN_BRACES, 0); + final PsiElement rBrace = PyUtil.getChildByFilter(parameters, PyTokenTypes.CLOSE_BRACES, 0); + final PyFunction pyFunction = as(parameters.getParent(), PyFunction.class); if (pyFunction != null && !PyFunctionFixer.isFakeFunction(pyFunction) && (lBrace == null || rBrace == null)) { final Document document = editor.getDocument(); if (lBrace == null) { final String textToInsert = pyFunction.getNameNode() == null ? " (" : "("; - document.insertString(psiElement.getTextOffset(), textToInsert); + document.insertString(parameters.getTextOffset(), textToInsert); + } + else if (parameters.getParameters().length == 0) { + document.insertString(lBrace.getTextRange().getEndOffset(), ")"); } else { - document.insertString(psiElement.getTextRange().getEndOffset(), ")"); + document.insertString(parameters.getTextRange().getEndOffset(), ")"); } } } diff --git a/python/testData/codeInsight/smartEnter/unclosedParametersListAndTrailingEmptyLines.py b/python/testData/codeInsight/smartEnter/unclosedParametersListAndTrailingEmptyLines.py new file mode 100644 index 000000000000..cf443c14153c --- /dev/null +++ b/python/testData/codeInsight/smartEnter/unclosedParametersListAndTrailingEmptyLines.py @@ -0,0 +1,2 @@ +def func( + diff --git a/python/testData/codeInsight/smartEnter/unclosedParametersListAndTrailingEmptyLines_after.py b/python/testData/codeInsight/smartEnter/unclosedParametersListAndTrailingEmptyLines_after.py new file mode 100644 index 000000000000..e0c59809be4d --- /dev/null +++ b/python/testData/codeInsight/smartEnter/unclosedParametersListAndTrailingEmptyLines_after.py @@ -0,0 +1,3 @@ +def func(): + + diff --git a/python/testSrc/com/jetbrains/python/PySmartEnterTest.java b/python/testSrc/com/jetbrains/python/PySmartEnterTest.java index 3ab0a309178c..03b195d12b80 100644 --- a/python/testSrc/com/jetbrains/python/PySmartEnterTest.java +++ b/python/testSrc/com/jetbrains/python/PySmartEnterTest.java @@ -185,6 +185,12 @@ public class PySmartEnterTest extends PyTestCase { doTest(); } + + // PY-15656 + public void testUnclosedParametersListAndTrailingEmptyLines() { + doTest(); + } + // PY-12877 public void testWithTargetOmitted() { doTest();