diff --git a/functions.py b/functions.py index a6ded459..f82d9836 100644 --- a/functions.py +++ b/functions.py @@ -180,7 +180,7 @@ def prepare_goto(source, position, source_path, module, goto_path, user_stmt = module.parser.user_stmt if isinstance(user_stmt, parsing.Import): - scopes = [imports.ImportPath2(user_stmt, is_like_search)] + scopes = [imports.ImportPath(user_stmt, is_like_search)] else: # just parse one statement, take it and evaluate it r = parsing.PyFuzzyParser(goto_path, source_path) @@ -239,13 +239,18 @@ def goto(source, line, column, source_path): try: definitions = [evaluate.statement_path[1]] except IndexError: - definitions = scopes + definitions = [] + for s in scopes: + if isinstance(s, imports.ImportPath): + definitions += s.follow() + else: + definitions.append(s) else: names = [] #print 's', scopes for s in scopes: names += s.get_defined_names() - definitions = [n.parent for n in names if n.names[-1] == search_name] + definitions = [n for n in names if n.names[-1] == search_name] #print evaluate.statement_path #print scopes, definitions _clear_caches() diff --git a/imports.py b/imports.py index 66edb4de..6b4b83a1 100644 --- a/imports.py +++ b/imports.py @@ -132,7 +132,6 @@ class ImportPath(object): f = builtin.Parser(name=path) return f.parser.top, rest -ImportPath2 = ImportPath def strip_imports(scopes): diff --git a/parsing.py b/parsing.py index 7c1697fe..dd9d4b3f 100644 --- a/parsing.py +++ b/parsing.py @@ -231,7 +231,7 @@ class Module(Scope): The top scope, which is always a module. """ def __init__(self, path, docstr=''): - super(Module, self).__init__((0, 0), docstr) + super(Module, self).__init__((1, 0), docstr) self.path = path self.global_vars = [] @@ -1253,6 +1253,7 @@ class PyFuzzyParser(object): else: stmt = stmt_class(string, set_vars, used_funcs, used_vars, \ tok_list, first_pos, self.end_pos) + self.check_user_stmt(stmt) if is_return: # add returns to the scope func = self.scope.get_parent_until(Function) diff --git a/plugin/jedi.vim b/plugin/jedi.vim index 0d6996bb..d99cc420 100644 --- a/plugin/jedi.vim +++ b/plugin/jedi.vim @@ -18,7 +18,6 @@ function! jedi#complete(findstart, base) python << PYTHONEOF if 1: row, column = vim.current.window.cursor - print if vim.eval('a:findstart') == '1': count = 0 for char in reversed(vim.current.line[:column]): diff --git a/test/run.py b/test/run.py index 809170b5..648333e9 100755 --- a/test/run.py +++ b/test/run.py @@ -113,10 +113,15 @@ def run_goto_test(correct, source, line_nr, line, path): r = r.definition if isinstance(r, evaluate.InstanceElement): r = r.var + if isinstance(r, evaluate.parsing.Name): + r = r.parent + if isinstance(r, (evaluate.Class, evaluate.Instance)): r = 'class ' + str(r.name) elif isinstance(r, (evaluate.Function, evaluate.parsing.Function)): r = 'def ' + str(r.name) + elif isinstance(r, evaluate.parsing.Module): + r = 'module ' + str(r.path) else: r = r.get_code().replace('\n', '') lst.append(r) @@ -124,7 +129,6 @@ def run_goto_test(correct, source, line_nr, line, path): if comp_str != correct: print('Solution @%s not right, received %s, wanted %s'\ % (line_nr - 1, comp_str, correct)) - print result return 1 return 0