forked from VimPlug/jedi
Fix issues with dynamic class parameter completion.
This commit is contained in:
@@ -246,7 +246,9 @@ class Evaluator(object):
|
|||||||
|
|
||||||
@debug.increase_indent
|
@debug.increase_indent
|
||||||
def execute(self, obj, arguments=(), trailer=None):
|
def execute(self, obj, arguments=(), trailer=None):
|
||||||
arguments = param.Arguments(self, arguments, trailer)
|
if not isinstance(arguments, param.Arguments):
|
||||||
|
arguments = param.Arguments(self, arguments, trailer)
|
||||||
|
|
||||||
if obj.isinstance(er.Function):
|
if obj.isinstance(er.Function):
|
||||||
obj = obj.get_decorated_func()
|
obj = obj.get_decorated_func()
|
||||||
|
|
||||||
|
|||||||
@@ -43,16 +43,16 @@ class ParamListener(object):
|
|||||||
@memoize_default([], evaluator_is_first_arg=True)
|
@memoize_default([], evaluator_is_first_arg=True)
|
||||||
def search_params(evaluator, param):
|
def search_params(evaluator, param):
|
||||||
"""
|
"""
|
||||||
This is a dynamic search for params. If you try to complete a type:
|
A dynamic search for param values. If you try to complete a type:
|
||||||
|
|
||||||
>>> def func(foo):
|
>>> def func(foo):
|
||||||
... foo
|
... foo
|
||||||
>>> func(1)
|
>>> func(1)
|
||||||
>>> func("")
|
>>> func("")
|
||||||
|
|
||||||
It is not known what the type is, because it cannot be guessed with
|
It is not known what the type ``foo`` without analysing the whole code. You
|
||||||
recursive madness. Therefore one has to analyse the statements that are
|
have to look for all calls to ``func`` to find out what ``foo`` possibly
|
||||||
calling the function, as well as analyzing the incoming params.
|
is.
|
||||||
"""
|
"""
|
||||||
if not settings.dynamic_params:
|
if not settings.dynamic_params:
|
||||||
return []
|
return []
|
||||||
@@ -82,7 +82,10 @@ def search_params(evaluator, param):
|
|||||||
|
|
||||||
# TODO why not a direct comparison? functions seem to be
|
# TODO why not a direct comparison? functions seem to be
|
||||||
# decorated in types and not in compare...
|
# decorated in types and not in compare...
|
||||||
if compare.base in [t.base for t in types if hasattr(t, 'base')]:
|
c = [getattr(escope, 'base_func', None) or escope.base
|
||||||
|
for escope in types
|
||||||
|
if escope.isinstance(er.Function, er.Class)]
|
||||||
|
if compare in c:
|
||||||
# Only if we have the correct function we execute
|
# Only if we have the correct function we execute
|
||||||
# it, otherwise just ignore it.
|
# it, otherwise just ignore it.
|
||||||
evaluator.eval_trailer(types, trailer)
|
evaluator.eval_trailer(types, trailer)
|
||||||
@@ -146,10 +149,11 @@ def search_params(evaluator, param):
|
|||||||
current_module = param.get_parent_until()
|
current_module = param.get_parent_until()
|
||||||
func_name = unicode(func.name)
|
func_name = unicode(func.name)
|
||||||
compare = func
|
compare = func
|
||||||
if func_name == '__init__' and isinstance(func.parent, pr.Class):
|
if func_name == '__init__':
|
||||||
func_name = unicode(func.parent.name)
|
cls = func.get_parent_scope()
|
||||||
compare = func.parent
|
if isinstance(cls, pr.Class):
|
||||||
compare = er.wrap(evaluator, compare)
|
func_name = unicode(cls.name)
|
||||||
|
compare = cls
|
||||||
|
|
||||||
# add the listener
|
# add the listener
|
||||||
listener = ParamListener()
|
listener = ParamListener()
|
||||||
|
|||||||
Reference in New Issue
Block a user