diff --git a/builtin.py b/builtin.py index 8a7825dc..291436f1 100644 --- a/builtin.py +++ b/builtin.py @@ -244,5 +244,8 @@ class _Builtin(object): def scope(self): return self._builtins.parser.top + def get_defined_names(self): + return self.scope.get_defined_names() + Builtin = _Builtin() diff --git a/evaluate.py b/evaluate.py index 1a25d9f3..43126442 100644 --- a/evaluate.py +++ b/evaluate.py @@ -187,8 +187,12 @@ class Execution(Exec): (self.__class__.__name__, self.base) -def get_names_for_scope(scope): - """ Get all completions possible for the current scope. """ +def get_names_for_scope(scope, star_search=True): + """ + Get all completions possible for the current scope. + The star search option is only here to provide an optimization. Otherwise + the whole thing would make a little recursive maddness + """ compl = [] start_scope = scope while scope: @@ -199,6 +203,11 @@ def get_names_for_scope(scope): # add builtins to the global scope compl += builtin.Builtin.scope.get_defined_names() + + # add star imports + if star_search: + for s in remove_star_imports(start_scope.get_parent_until()): + compl += get_names_for_scope(s, star_search=False) #print 'gnfs', scope, compl return compl @@ -229,15 +238,6 @@ def get_scopes_for_name(scope, name, search_global=False): # the name is already given in the parent function result = [] for scope in scopes: - #if isinstance(scope, parsing.Import): - # try: - # debug.dbg('star import', scope) - # i = follow_import(scope).get_defined_names() - # except modules.ModuleNotFound: - # debug.dbg('StarImport not found: ' + str(scope)) - # else: - # result += filter_name(i) - #else: if [name] == list(scope.names): if isinstance(scope, ArrayElement): result.append(scope) @@ -410,10 +410,21 @@ def follow_import(_import): else: scopes = [scope] - for s in scopes: - scopes += strip_imports(i for i in s.get_imports() if i.star) + new = [] + for scope in scopes: + new += remove_star_imports(scope) + scopes += new debug.dbg('after import', scopes, rest) + return scopes + + +def remove_star_imports(scope): + modules = strip_imports(i for i in scope.get_imports() if i.star) + new = [] + for m in modules: + new += remove_star_imports(m) + modules += new # filter duplicate modules - return list(set(scopes)) + return list(set(modules)) diff --git a/ftest.py b/ftest.py index 5f4944c3..7f44c378 100755 --- a/ftest.py +++ b/ftest.py @@ -2,7 +2,7 @@ import functions -functions.debug.debug_function = functions.debug.print_to_stdout +#functions.debug.debug_function = functions.debug.print_to_stdout functions.debug.ignored_modules = ['parsing', 'builtin'] functions.debug.ignored_modules = ['parsing', 'builtin', 'evaluate', 'modules'] functions.modules.module_find_path.insert(0, '.') diff --git a/parsetest.py b/parsetest.py index 7a47dd91..91f31d7e 100644 --- a/parsetest.py +++ b/parsetest.py @@ -147,4 +147,4 @@ c = b().c3() 1.0.fromhex(); import flask ; flsk = flask.Flask + flask.Request; abc = [1,2+3]; abc[0]. import pylab -abc = datetime; return [abc][0]. +abc = datetime; return [abc][0]. ;pylab. diff --git a/parsing.py b/parsing.py index 16128ff2..6894df9c 100644 --- a/parsing.py +++ b/parsing.py @@ -244,7 +244,7 @@ class GlobalScope(Scope): def get_set_vars(self): n = super(GlobalScope, self).get_set_vars() n += self.global_vars - return n + return n class Class(Scope): @@ -1035,7 +1035,7 @@ class PyFuzzyParser(object): :return: Statement + last parsed token. :rtype: (Statement, str) - TODO improve abort criterion of not closing parentheses + TODO improve abort criterion of not closing parentheses """ string = '' @@ -1245,7 +1245,7 @@ class PyFuzzyParser(object): while 1: token_type, tok, indent = self.next() if tok != '.': - break; + break relative_count += 1 # the from import mod, token_type, tok, start_indent, start_line2 = \ diff --git a/test/completion/functions.py b/test/completion/functions.py index bcc2bad5..2bdbbd25 100644 --- a/test/completion/functions.py +++ b/test/completion/functions.py @@ -1,9 +1,15 @@ -import os def array(): return list() #? ['append'] -array().app +array().append #? ['array'] arr + + +def inputs(param): + return param + +#? ['append'] +inputs(list).append