mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-15656 Insert closing parenthesis of parameter list right after opening one if there are no parameters
This commit is contained in:
+9
-6
@@ -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(
|
||||
|
||||
+3
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user