From fd760f1870a51e014777be0a406ee3b52613a900 Mon Sep 17 00:00:00 2001 From: David Halter Date: Sat, 22 Sep 2012 00:15:32 +0200 Subject: [PATCH] renaming and goto work now +/- --- jedi/api.py | 8 ++------ jedi/dynamic.py | 2 +- jedi/evaluate.py | 15 +++++++++++---- jedi/imports.py | 22 ++++++++++++++-------- 4 files changed, 28 insertions(+), 19 deletions(-) diff --git a/jedi/api.py b/jedi/api.py index 9c4e1be2..e5812f5f 100644 --- a/jedi/api.py +++ b/jedi/api.py @@ -331,9 +331,7 @@ class Script(object): else: goto_path = self.module.get_path_under_cursor() stmt = self._get_under_cursor_stmt(goto_path) - arr = stmt.get_assignment_calls() - call = arr.get_only_subelement() - definitions, search_name = evaluate.goto3(call) + definitions, search_name = evaluate.goto3(stmt) #scopes = self._prepare_goto(goto_path) #definitions = evaluate.goto(scopes, search_name_new) @@ -370,9 +368,7 @@ class Script(object): else: goto_path = self.module.get_path_under_cursor() stmt = self._get_under_cursor_stmt(goto_path) - arr = stmt.get_assignment_calls() - call = arr.get_only_subelement() - definitions, search_name = evaluate.goto3(call) + definitions, search_name = evaluate.goto3(stmt) #print 'd', definitions, call, call.parent_stmt().parent().start_pos #evaluate.goto_names = [] #scopes = self._prepare_goto(goto_path) diff --git a/jedi/dynamic.py b/jedi/dynamic.py index e08b9db2..88c225c3 100644 --- a/jedi/dynamic.py +++ b/jedi/dynamic.py @@ -350,7 +350,7 @@ def related_names(definitions, search_name, mods): #follow_res = evaluate.goto(scopes, search, statement_path_offset=0, # follow_import=True) #follow_res = evaluate.goto2(scopes, search) - follow_res, search = evaluate.goto3(call, f) + follow_res, search = evaluate.goto3(call.parent_stmt(), f) # compare to see if they match if True in [r in definitions for r in follow_res]: diff --git a/jedi/evaluate.py b/jedi/evaluate.py index 3a7cbe8b..600e36e5 100644 --- a/jedi/evaluate.py +++ b/jedi/evaluate.py @@ -1513,11 +1513,17 @@ def follow_path(path, scope, position=None): return follow_paths(path, set(result), position=position) -def goto3(call, call_path=None): +def goto3(stmt, call_path=None): if call_path is None: + arr = stmt.get_assignment_calls() + call = arr.get_only_subelement() call_path = list(call.generate_call_path()) - scope = call.parent_stmt().parent() - pos = call.parent_stmt().start_pos + + scope = stmt.parent() + pos = stmt.start_pos + return goto3_dini_mueter(call_path, scope, pos) + +def goto3_dini_mueter(call_path, scope, pos): call_path, search = call_path[:-1], call_path[-1] if call_path: scopes = follow_call_path(iter(call_path), scope, pos) @@ -1530,10 +1536,11 @@ def goto3(call, call_path=None): for s in scopes: follow_res += get_scopes_for_name(s, search, pos, search_global=search_global, is_goto=True) - #print 'c', call, scope, follow_res + #print 'c', stmt, scope, follow_res return follow_res, search + def goto2(scopes, search_name=None): global goto_names result = goto_names diff --git a/jedi/imports.py b/jedi/imports.py index 0283ab35..ab12dfe6 100644 --- a/jedi/imports.py +++ b/jedi/imports.py @@ -11,6 +11,7 @@ import modules import debug import parsing import evaluate +import itertools class ModuleNotFound(Exception): @@ -138,17 +139,22 @@ class ImportPath(object): debug.warning('Module not found: ' + str(self.import_stmt)) return [] + scopes = [scope] + scopes += itertools.chain.from_iterable( + remove_star_imports(s) for s in scopes) + if len(rest) > 1 or rest and self.is_like_search: scopes = [] elif rest: - scopes = list(evaluate.follow_path(iter(rest), scope)) - else: - scopes = [scope] - - new = [] - for scope in scopes: - new += remove_star_imports(scope) - scopes += new + if is_goto: + #scopes = list(evaluate.follow_path(iter(rest), scope)) + #scopes = evaluate.goto3_dini_mueter(rest) + scopes = itertools.chain.from_iterable( + evaluate.get_scopes_for_name(s, rest[0], is_goto=True) + for s in scopes) + else: + scopes = evaluate.follow_path(iter(rest), scope) + scopes = list(scopes) if self.is_nested_import(): scopes.append(self.get_nested_import(scope))