mirror of
https://github.com/davidhalter/jedi.git
synced 2026-03-01 01:02:20 +08:00
rename / goto fully functional
This commit is contained in:
13
jedi/api.py
13
jedi/api.py
@@ -308,6 +308,7 @@ class Script(object):
|
||||
except IndexError:
|
||||
definitions = []
|
||||
search_name = str(name_part)
|
||||
|
||||
if add_import_name:
|
||||
import_name = self.parser.user_stmt.get_defined_names()
|
||||
# imports have only one name
|
||||
@@ -328,7 +329,10 @@ class Script(object):
|
||||
TODO implement additional_module_paths
|
||||
"""
|
||||
definitions, search_name = self._goto(add_import_name=True)
|
||||
definitions = dynamic.related_name_add_import_modules(definitions)
|
||||
if not isinstance(self.parser.user_stmt, parsing.Import):
|
||||
# import case is looked at with add_import_name option
|
||||
definitions = dynamic.related_name_add_import_modules(definitions,
|
||||
search_name)
|
||||
|
||||
module = set([d.get_parent_until() for d in definitions])
|
||||
module.add(self.parser.module)
|
||||
@@ -418,15 +422,14 @@ class Script(object):
|
||||
def _get_on_import_stmt(self, is_like_search=False):
|
||||
user_stmt = self.parser.user_stmt
|
||||
import_names = user_stmt.get_all_import_names()
|
||||
count = 0
|
||||
kill_count = -1
|
||||
cur_name_part = None
|
||||
for i in import_names:
|
||||
for name_part in i.names:
|
||||
count += 1
|
||||
if self.pos <= name_part.end_pos:
|
||||
if name_part.end_pos >= self.pos:
|
||||
if not cur_name_part:
|
||||
cur_name_part = name_part
|
||||
kill_count += 1
|
||||
cur_name_part = name_part
|
||||
|
||||
i = imports.ImportPath(user_stmt, is_like_search,
|
||||
kill_count=kill_count, direct_resolve=True)
|
||||
|
||||
@@ -348,7 +348,7 @@ 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)
|
||||
follow_res = related_name_add_import_modules(follow_res, search)
|
||||
|
||||
#print follow_res, [d.parent() for d in follow_res]
|
||||
# compare to see if they match
|
||||
@@ -381,9 +381,9 @@ def related_names(definitions, search_name, mods):
|
||||
if name_part == search_name:
|
||||
imps.append((count, name_part))
|
||||
|
||||
for kill_count, name_part in imps:
|
||||
i = imports.ImportPath(stmt, False,
|
||||
kill_count=count - kill_count, direct_resolve=True)
|
||||
for used_count, name_part in imps:
|
||||
i = imports.ImportPath(stmt, kill_count=count - used_count,
|
||||
direct_resolve=True)
|
||||
f = i.follow(is_goto=True)
|
||||
if set(f) & set(definitions):
|
||||
names.append(RelatedName(name_part, stmt))
|
||||
@@ -393,13 +393,12 @@ def related_names(definitions, search_name, mods):
|
||||
names += check_call(call)
|
||||
return names
|
||||
|
||||
def related_name_add_import_modules(definitions):
|
||||
def related_name_add_import_modules(definitions, search_name):
|
||||
""" Adds the modules of the imports """
|
||||
new = set()
|
||||
for d in definitions:
|
||||
if isinstance(d.parent(), parsing.Import):
|
||||
# TODO introduce kill_count for not fully used imports
|
||||
s = imports.ImportPath(d.parent(), False, direct_resolve=True)
|
||||
s = imports.ImportPath(d.parent(), direct_resolve=True)
|
||||
try:
|
||||
new.add(s.follow(is_goto=True)[0])
|
||||
except IndexError:
|
||||
|
||||
Reference in New Issue
Block a user