From 0c71a9d86a0052139da6dda61f99e783c2c030bd Mon Sep 17 00:00:00 2001 From: David Halter Date: Sat, 22 Sep 2012 01:48:17 +0200 Subject: [PATCH] renaming works now a little bit better with modules --- jedi/api.py | 5 ++++- jedi/dynamic.py | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/jedi/api.py b/jedi/api.py index df277ad0..19fafa31 100644 --- a/jedi/api.py +++ b/jedi/api.py @@ -339,7 +339,8 @@ class Script(object): This function can be used either to show all the usages of a variable or for renaming purposes. """ - definitions, search_name = self._goto(check_imports=False) + definitions, search_name = self._goto(check_imports=True) + definitions = dynamic.related_name_add_import_modules(definitions) module = set([d.get_parent_until() for d in definitions]) module.add(self.parser.module) @@ -372,6 +373,8 @@ class Script(object): names.append(dynamic.RelatedName(n, d)) elif isinstance(d, parsing.Name): names.append(dynamic.RelatedName(d.names[0], d)) + elif isinstance(d, parsing.Module): + names.append(dynamic.RelatedName(d.get_names(), d)) else: names.append(dynamic.RelatedName(d.name.names[0], d)) diff --git a/jedi/dynamic.py b/jedi/dynamic.py index d1bacd0e..2e62d03f 100644 --- a/jedi/dynamic.py +++ b/jedi/dynamic.py @@ -17,6 +17,7 @@ import helpers import settings import debug import builtin +import imports # This is something like the sys.path, but only for searching params. It means # that this is the order in which Jedi searches params. @@ -347,7 +348,9 @@ def related_names(definitions, search_name, mods): for f in follow: follow_res, search = evaluate.goto(call.parent_stmt(), f) + follow_res = related_name_add_import_modules(follow_res) + #print follow_res, [d.parent() for d in follow_res] # compare to see if they match if True in [r in definitions for r in follow_res]: scope = call.parent_stmt() @@ -366,10 +369,25 @@ def related_names(definitions, search_name, mods): except KeyError: continue for stmt in stmts: + print stmt for call in _scan_array(stmt.get_assignment_calls(), search_name): names += check_call(call) return names +def related_name_add_import_modules(definitions): + """ Adds the modules of the imports """ + new = [] + for d in definitions: + if isinstance(d.parent(), parsing.Import): + # introduce kill_count for not fully used imports + s = imports.ImportPath(d.parent(), False, direct_resolve=True) + try: + new.append(s.follow(is_goto=True)[0]) + except IndexError: + pass + return definitions + new + + class BaseOutput(object): def __init__(self, start_pos, definition):