diff --git a/evaluate.py b/evaluate.py index 2867bad4..70f7ffe9 100644 --- a/evaluate.py +++ b/evaluate.py @@ -391,18 +391,20 @@ def get_scopes_for_name(scope, name_str, position=None, search_global=False): return result result = [] + # compare func uses the tuple of line/indent = row/column + comparison_func = lambda name: (name.line_nr, name.indent) for scope, name_list in scope_generator: - for name in sorted(name_list, key=lambda name: name.line_nr, - reverse=True): + # here is the position stuff happening (sorting of variables) + for name in sorted(name_list, key=comparison_func, reverse=True): if name_str == name.get_code(): if isinstance(name, ArrayElement): # TODO why? don't know why this exists, was if/else raise Exception('dini mueter, wieso?' + str(name)) result.append(name) result += handle_non_arrays(name) + #print name, name.parent.parent, scope # this means that a definition was found and is not e.g. # in if/else. - #print name, name.parent.parent, scope if name.parent.parent == scope: break # if there are results, ignore the other scopes diff --git a/test/completion/functions.py b/test/completion/functions.py index ee6f7bdc..03bea797 100644 --- a/test/completion/functions.py +++ b/test/completion/functions.py @@ -39,8 +39,31 @@ def variable_rename(param): #? ['imag'] variable_rename(1).imag -# double execution -> shouldn't work (and throw no error) +# ----------------- +# double execution +# ----------------- +def double_exe(param): + return param + +#? ['upper'] +variable_rename(double_exe)("").upper + +# -> shouldn't work (and throw no error) #? [] variable_rename(list())(). #? [] variable_rename(1)(). + +# ----------------- +# closures +# ----------------- +def a(): + l = 3 + def func_b(): + #? ['real'] + l.real + l = '' + #? ['func_b'] + func_b + #? ['real'] + l.real diff --git a/test/completion/ordering.py b/test/completion/ordering.py index d6381d37..408de135 100644 --- a/test/completion/ordering.py +++ b/test/completion/ordering.py @@ -1,4 +1,6 @@ +# ----------------- # normal +# ----------------- a = "" a = 1 @@ -9,10 +11,41 @@ a.upper #? [] a.append - a = list +b ="";b=1 +#? ['real'] +b.real +#? [] +b.upper + +# ----------------- +# tuples exchanges +# ----------------- +a, b = 1, "" +#? ['real'] +a.real +#? [] +a.upper +#? [] +b.real +#? ['upper'] +b.upper + +b, a = a, b +#? ['real'] +b.real +#? [] +b.upper +#? [] +a.real +#? ['upper'] +a.upper + + +# ----------------- # function stuff +# ----------------- def a(a=3): #? ['real'] a.real @@ -28,8 +61,9 @@ a(2).real a(2).upper #? [] a(2).func - +# ----------------- # class stuff +# ----------------- class A(object): a = "" a = 3 @@ -59,13 +93,61 @@ class A(object): #? ['upper'] self.a.upper + #? ['after'] + self.after + def after(self): self.a = '' -##? ['real'] +#? [] A.a.real -##? [] +#? [] A.a.upper -##? [] +#? ['append'] A.a.append +a = A() +#? ['after'] +a.after +#? [] +a.upper +#? [] +a.append +#? [] +a.real + +#? ['append'] +a.a.append +#? ['real'] +a.a.real +#? ['upper'] +a.a.upper + +# ----------------- +# class stuff +# ----------------- + +math = 3 +import math +#? ['cosh'] +math.cosh +#? [] +math.real + +math = 3 +#? ['real'] +math.real +#? [] +math.cos + +# do the same for star imports +cosh = 3 +from math import * +# This doesn't work, but that's not a problem, star imports should be at the +# start of EVERY script! +##? [] +cosh.real + +cosh = 3 +#? ['real'] +cosh.real diff --git a/test/completion/types.py b/test/completion/types.py index f563416f..b754816f 100644 --- a/test/completion/types.py +++ b/test/completion/types.py @@ -72,7 +72,7 @@ tup.c tup2 = tuple() #? ['index'] tup2.i -##? ['index'] TODO enable +#? ['index'] ().i tup3 = 1,"" diff --git a/test/run.py b/test/run.py index fb6bd023..26a62cc9 100755 --- a/test/run.py +++ b/test/run.py @@ -35,7 +35,7 @@ def completion_test(source): completions = functions.complete(source, line_nr, 999, completion_test_dir) except: - print 'test @#%s: %s' % (line_nr-1, line) + print 'test @%s: %s' % (line_nr-1, line) print traceback.format_exc() fails += 1 else: @@ -43,7 +43,7 @@ def completion_test(source): # TODO remove set! duplicates should not be normal comp_str = str(sorted(set([str(c) for c in completions]))) if comp_str != correct: - print 'Solution on @#%s not right, received %s, wanted %s'\ + print 'Solution @%s not right, received %s, wanted %s'\ % (line_nr - 1, comp_str, correct) #print [(c.name, c.name.parent) for c in completions] fails += 1