From fdfd475d40a6f0216cc4392b1401586dc01b35ae Mon Sep 17 00:00:00 2001 From: David Halter Date: Fri, 6 Jul 2012 01:07:17 +0200 Subject: [PATCH] position stuff works now also with function that are located after the just called function --- evaluate.py | 13 +++++++++---- test/completion/classes.py | 22 ++++++++++++++++++++++ test/completion/functions.py | 19 ++++++++++++++++++- 3 files changed, 49 insertions(+), 5 deletions(-) diff --git a/evaluate.py b/evaluate.py index 1bbc59fb..be452ee7 100644 --- a/evaluate.py +++ b/evaluate.py @@ -771,7 +771,7 @@ class ArrayElement(object): return "<%s of %s>" % (self.__class__.__name__, self.name) -def get_defined_names_for_position(obj, position=None): +def get_defined_names_for_position(obj, position=None, start_scope=None): """ :param position: the position as a row/column tuple, default is infinity. """ @@ -779,7 +779,9 @@ def get_defined_names_for_position(obj, position=None): # instances have special rules, always return all the possible completions, # because class variables are always valid and the `self.` variables, too. if not position or isinstance(obj, Instance) or isinstance(obj, Function) \ - and isinstance(obj.decorated_func, Instance): + and isinstance(obj.decorated_func, Instance) \ + or start_scope != obj and isinstance(start_scope, + (parsing.Function, Execution)): return names names_new = [] for n in names: @@ -799,9 +801,12 @@ def get_names_for_scope(scope, position=None, star_search=True): # `parsing.Class` is used, because the parent is never `Class`. # ignore the Flows, because the classes and functions care for that. if not (scope != start_scope and isinstance(scope, parsing.Class) - or isinstance(scope, parsing.Flow)): + or isinstance(scope, parsing.Flow) + or isinstance(scope, InstanceElement) + and isinstance(scope.var, parsing.Class)): try: - yield scope, get_defined_names_for_position(scope, position) + yield scope, get_defined_names_for_position(scope, position, + start_scope) except StopIteration: raise MultiLevelStopIteration('StopIteration raised somewhere') scope = scope.parent diff --git a/test/completion/classes.py b/test/completion/classes.py index d2979537..9b842046 100644 --- a/test/completion/classes.py +++ b/test/completion/classes.py @@ -187,3 +187,25 @@ class V: ##? int() V().b() + +# ----------------- +# ordering +# ----------------- +class A(): + def b(self): + #? int() + a() + #? str() + self.a() + return a() + + def a(self): + return "" + +def a(): + return 1 + +#? int() +A().b() +#? str() +A().a() diff --git a/test/completion/functions.py b/test/completion/functions.py index 146c7195..c5e2ddd7 100644 --- a/test/completion/functions.py +++ b/test/completion/functions.py @@ -1,4 +1,3 @@ - def array(first_param): #? ['first_param'] first_param @@ -66,6 +65,24 @@ def recursion(a, b): ##? int() float() recursion("a", 1.0) +# ----------------- +# ordering +# ----------------- + +#def b(): + #return "" + +def a(): + #? int() + b() + return b() + +def b(): + return 1 + +#? int() +a() + # ----------------- # keyword arguments # -----------------