diff --git a/jedi/api.py b/jedi/api.py index c3daf4bc..a8632a2c 100644 --- a/jedi/api.py +++ b/jedi/api.py @@ -227,8 +227,7 @@ class Script(object): return c def _prepare_goto(self, goto_path, is_like_search=False): - scope = self.parser.user_scope - debug.dbg('start: %s in %s' % (goto_path, scope)) + debug.dbg('start: %s in %s' % (goto_path, self.parser.scope)) user_stmt = self.parser.user_stmt if not user_stmt and len(goto_path.split('\n')) > 1: @@ -250,18 +249,20 @@ class Script(object): kill_count=kill_count, direct_resolve=True)] else: # just parse one statement, take it and evaluate it - r = parsing.PyFuzzyParser(goto_path, self.source_path, - no_docstr=True) - try: - stmt = r.module.statements[0] - except IndexError: - raise NotFoundError() - - stmt.start_pos = self.pos - stmt.parent = weakref.ref(scope) + stmt = self._get_under_cursor_stmt(goto_path) scopes = evaluate.follow_statement(stmt) return scopes + def _get_under_cursor_stmt(self, cursor_txt): + r = parsing.PyFuzzyParser(cursor_txt, self.source_path, no_docstr=True) + try: + stmt = r.module.statements[0] + except IndexError: + raise NotFoundError() + stmt.start_pos = self.pos + stmt.parent = weakref.ref(self.parser.user_scope) + return stmt + def get_definition(self): """ Returns the definitions of a the path under the cursor. This is @@ -346,13 +347,22 @@ class Script(object): #(parsing.Param, parsing.Import)): #definitions = [self.module.parser.user_stmt] else: - evaluate.goto_names = [] - scopes = self._prepare_goto(goto_path) - definitions = evaluate.goto2(scopes, search_name_new) + 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) + #print 'd', definitions, call, call.parent_stmt().parent().start_pos + #evaluate.goto_names = [] + #scopes = self._prepare_goto(goto_path) + #definitions = evaluate.goto2(scopes, search_name_new) module = set([d.get_parent_until() for d in definitions]) module.add(self.module.parser.module) - names = dynamic.related_names(definitions, search_name, module) + if definitions: + names = dynamic.related_names(definitions, search_name, module) + else: + names = [] for d in definitions: if isinstance(d, parsing.Statement): diff --git a/jedi/dynamic.py b/jedi/dynamic.py index b8333590..e08b9db2 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(f, call) + follow_res, search = evaluate.goto3(call, 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 3811eda1..3a7cbe8b 100644 --- a/jedi/evaluate.py +++ b/jedi/evaluate.py @@ -1513,23 +1513,24 @@ def follow_path(path, scope, position=None): return follow_paths(path, set(result), position=position) -def goto3(call_path, call): +def goto3(call, call_path=None): + if call_path is None: + call_path = list(call.generate_call_path()) scope = call.parent_stmt().parent() - position = call.parent_stmt().start_pos + pos = call.parent_stmt().start_pos call_path, search = call_path[:-1], call_path[-1] if call_path: - scopes = follow_call_path(iter(call_path), scope, position) + scopes = follow_call_path(iter(call_path), scope, pos) search_global = False pos = None else: scopes = [scope] - pos = search.start_pos search_global = True follow_res = [] 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', call, scope, follow_res return follow_res, search diff --git a/test/completion/import_tree/rename2.py b/test/completion/import_tree/rename2.py index b9776007..8423895d 100644 --- a/test/completion/import_tree/rename2.py +++ b/test/completion/import_tree/rename2.py @@ -1,5 +1,6 @@ """ used for renaming tests """ + from rename1 import abc abc diff --git a/test/completion/renaming.py b/test/completion/renaming.py index 817db71b..0ca2ec5c 100644 --- a/test/completion/renaming.py +++ b/test/completion/renaming.py @@ -67,12 +67,12 @@ import colorama #< (65,7) (68,0) colorama -#< 3 -import abc + + from import_tree import rename1 -##< (78,8) (3,0) +#< (78,8) (3,0) (4,20) (6,0) rename1.abc