mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-3999 : Context passed to Keyword Argument Completion to allow better completion
This commit is contained in:
@@ -219,7 +219,7 @@ public class PyNamedParameterImpl extends PyBaseElementImpl<PyNamedParameterStub
|
||||
final PyClass containingClass = func.getContainingClass();
|
||||
if (containingClass != null) {
|
||||
PyType initType = null;
|
||||
final PyFunction init = containingClass.findInitOrNew(true, null);
|
||||
final PyFunction init = containingClass.findInitOrNew(true, context);
|
||||
if (init != null && init != func) {
|
||||
initType = context.getReturnType(init);
|
||||
if (init.getContainingClass() != containingClass) {
|
||||
|
||||
+3
-2
@@ -34,12 +34,13 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
public class KeywordArgumentCompletionUtil {
|
||||
public static void collectFunctionArgNames(PyElement element, List<LookupElement> ret) {
|
||||
public static void collectFunctionArgNames(PyElement element, List<LookupElement> ret, final @NotNull TypeEvalContext context) {
|
||||
PyCallExpression callExpr = PsiTreeUtil.getParentOfType(element, PyCallExpression.class);
|
||||
if (callExpr != null) {
|
||||
PyExpression callee = callExpr.getCallee();
|
||||
if (callee instanceof PyReferenceExpression && element.getParent() == callExpr.getArgumentList()) {
|
||||
final QualifiedResolveResult result = ((PyReferenceExpression)callee).followAssignmentsChain(PyResolveContext.defaultContext());
|
||||
final PyResolveContext resolveContext = PyResolveContext.defaultContext().withTypeEvalContext(context);
|
||||
final QualifiedResolveResult result = ((PyReferenceExpression)callee).followAssignmentsChain(resolveContext);
|
||||
PsiElement def = result.getElement();
|
||||
if (def instanceof PyFunction) {
|
||||
addKeywordArgumentVariants((PyFunction)def, callExpr, ret);
|
||||
|
||||
@@ -578,8 +578,9 @@ public class PyReferenceImpl implements PsiReferenceEx, PsiPolyVariantReference
|
||||
PyResolveUtil.scopeCrawlUp(processor, owner, null, null);
|
||||
}
|
||||
|
||||
// This method is probably called for completion, so use appropriate context here
|
||||
// in a call, include function's arg names
|
||||
KeywordArgumentCompletionUtil.collectFunctionArgNames(element, ret);
|
||||
KeywordArgumentCompletionUtil.collectFunctionArgNames(element, ret, TypeEvalContext.codeCompletion(element.getProject(), element.getContainingFile()));
|
||||
|
||||
// include builtin names
|
||||
final PyFile builtinsFile = PyBuiltinCache.getInstance(element).getBuiltinsFile();
|
||||
|
||||
Reference in New Issue
Block a user