mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-15640 Ignore smart enter fixers in case of empty PyFunction created only to wrap list of decorators
This commit is contained in:
+5
-1
@@ -41,10 +41,14 @@ public class PyFunctionFixer extends PyFixer<PyFunction> {
|
||||
public void doApply(@NotNull Editor editor, @NotNull PySmartEnterProcessor processor, @NotNull PyFunction function)
|
||||
throws IncorrectOperationException {
|
||||
final PsiElement colon = PyUtil.getFirstChildOfType(function, PyTokenTypes.COLON);
|
||||
if (colon == null) {
|
||||
if (!isFakeFunction(function) && colon == null) {
|
||||
final PyParameterList parameterList = function.getParameterList();
|
||||
final Document document = editor.getDocument();
|
||||
document.insertString(parameterList.getTextRange().getEndOffset(), ":");
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isFakeFunction(PyFunction function) {
|
||||
return function.getNode().findChildByType(PyTokenTypes.DEF_KEYWORD) == null;
|
||||
}
|
||||
}
|
||||
|
||||
+9
-1
@@ -21,10 +21,13 @@ import com.intellij.psi.PsiElement;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.jetbrains.python.PyTokenTypes;
|
||||
import com.jetbrains.python.codeInsight.editorActions.smartEnter.PySmartEnterProcessor;
|
||||
import com.jetbrains.python.psi.PyFunction;
|
||||
import com.jetbrains.python.psi.PyParameterList;
|
||||
import com.jetbrains.python.psi.PyUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static com.jetbrains.python.psi.PyUtil.as;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* Author: Alexey.Ivanov
|
||||
@@ -40,7 +43,7 @@ public class PyParameterListFixer extends PyFixer<PyParameterList> {
|
||||
public void doApply(@NotNull Editor editor, @NotNull PySmartEnterProcessor processor, @NotNull PyParameterList psiElement) throws IncorrectOperationException {
|
||||
final PsiElement lBrace = PyUtil.getChildByFilter(psiElement, PyTokenTypes.OPEN_BRACES, 0);
|
||||
final PsiElement rBrace = PyUtil.getChildByFilter(psiElement, PyTokenTypes.CLOSE_BRACES, 0);
|
||||
if (lBrace == null || rBrace == null) {
|
||||
if (!isFakeParameterList(psiElement) && (lBrace == null || rBrace == null)) {
|
||||
final Document document = editor.getDocument();
|
||||
if (lBrace == null) {
|
||||
document.insertString(psiElement.getTextRange().getStartOffset(), "(");
|
||||
@@ -50,4 +53,9 @@ public class PyParameterListFixer extends PyFixer<PyParameterList> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isFakeParameterList(@NotNull PyParameterList parameterList) {
|
||||
final PyFunction pyFunction = as(parameterList.getParent(), PyFunction.class);
|
||||
return pyFunction != null && pyFunction.getNode().findChildByType(PyTokenTypes.DEF_KEYWORD) == null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user