PY-15656 Insert closing parenthesis of parameter list right after opening one if there are no parameters

This commit is contained in:
Mikhail Golubev
2015-04-21 15:14:26 +03:00
parent 246fcae221
commit fbbf4dcade
4 changed files with 20 additions and 6 deletions
@@ -40,19 +40,22 @@ public class PyParameterListFixer extends PyFixer<PyParameterList> {
}
@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(), ")");
}
}
}
@@ -0,0 +1,2 @@
def fun<caret>c(
@@ -0,0 +1,3 @@
def func():
<caret>
@@ -185,6 +185,12 @@ public class PySmartEnterTest extends PyTestCase {
doTest();
}
// PY-15656
public void testUnclosedParametersListAndTrailingEmptyLines() {
doTest();
}
// PY-12877
public void testWithTargetOmitted() {
doTest();