1
0
forked from VimPlug/jedi

renaming works now a little bit better with modules

This commit is contained in:
David Halter
2012-09-22 01:48:17 +02:00
parent 7dc96502eb
commit 0c71a9d86a
2 changed files with 22 additions and 1 deletions

View File

@@ -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))

View File

@@ -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):