don't add parentheses when completing single-arg decorator (PY-2210)

This commit is contained in:
Dmitry Jemerov
2010-11-01 22:42:12 +03:00
parent 98dfa241ae
commit bd46ea9bf2
5 changed files with 30 additions and 2 deletions
@@ -176,6 +176,10 @@ public class PyCallExpressionHelper {
) {
//return getImplicitArgumentCount(functionBeingCalled, null, null, qualifierIsAnInstance(callReference, TypeEvalContext.fast()));
if (typeContext == null) typeContext = TypeEvalContext.fast();
final PyDecorator decorator = PsiTreeUtil.getParentOfType(callReference, PyDecorator.class);
if (decorator != null && PsiTreeUtil.isAncestor(decorator.getCallee(), callReference, false)) {
return 1;
}
QualifiedResolveResult followed = callReference.followAssignmentsChain(typeContext);
return getImplicitArgumentCount(functionBeingCalled, null, null, isQualifiedByInstance(functionBeingCalled, followed.getLastQualifier(), typeContext));
}
@@ -8,6 +8,7 @@ import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiNamedElement;
import com.intellij.psi.ResolveState;
import com.intellij.psi.scope.PsiScopeProcessor;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.Icons;
import com.jetbrains.python.codeInsight.PyClassInsertHandler;
import com.jetbrains.python.codeInsight.PyFunctionInsertHandler;
@@ -56,7 +57,8 @@ public class VariantsProcessor implements PsiScopeProcessor {
protected LookupElementBuilder setupItem(LookupElementBuilder item) {
if (!myPlainNamesOnly) {
if (item.getObject() instanceof PyFunction && ((PyFunction) item.getObject()).getProperty() == null) {
if (item.getObject() instanceof PyFunction && ((PyFunction) item.getObject()).getProperty() == null &&
!isSingleArgDecoratorCall(myContext, (PyFunction)item.getObject())) {
item = item.setInsertHandler(PyFunctionInsertHandler.INSTANCE);
}
else if (item.getObject() instanceof PyClass) {
@@ -69,6 +71,17 @@ public class VariantsProcessor implements PsiScopeProcessor {
return item;
}
private static boolean isSingleArgDecoratorCall(PsiElement elementInCall, PyFunction callee) {
if (callee.getParameterList().getParameters().length > 1) {
return false;
}
PyDecorator decorator = PsiTreeUtil.getParentOfType(elementInCall, PyDecorator.class);
if (decorator == null) {
return false;
}
return PsiTreeUtil.isAncestor(decorator.getCallee(), elementInCall, false);
}
protected static LookupElementBuilder setItemNotice(final LookupElementBuilder item, String notice) {
return item.setTypeText(notice);
}
@@ -0,0 +1,4 @@
def my_decorator(f):
return f
@my_decorator<caret>
@@ -0,0 +1,4 @@
def my_decorator(f):
return f
@my_deco<caret>
@@ -5,7 +5,6 @@
package com.jetbrains.python;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.openapi.application.ApplicationManager;
import com.jetbrains.python.fixtures.PyLightFixtureTestCase;
import java.util.Arrays;
@@ -224,4 +223,8 @@ public class PythonCompletionTest extends PyLightFixtureTestCase {
myFixture.completeBasic();
myFixture.checkResultByFile(dirname + "importedModule.after.py");
}
public void testNoParensForDecorator() { // PY-2210
doTest();
}
}