1
0
forked from VimPlug/jedi

rename / goto fully functional

This commit is contained in:
David Halter
2012-09-22 17:20:51 +02:00
parent 5982c7c93d
commit 78f2059c12
3 changed files with 21 additions and 16 deletions

View File

@@ -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:
kill_count += 1
if name_part.end_pos >= self.pos:
if not cur_name_part:
cur_name_part = name_part
kill_count += 1
i = imports.ImportPath(user_stmt, is_like_search,
kill_count=kill_count, direct_resolve=True)

View File

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

View File

@@ -71,15 +71,18 @@ module_not_exists
#< (1,0), (85,17), (75,24), (78,0), (81,17), (4,5)
#< (1,0), (75,24), (78,0), (81,17), (4,5), (85,17), (88,17)
from import_tree import rename1
#< (78,8), (3,0), (4,20), (6,0), (81,32), (82,0)
#< (78,8), (3,0), (4,20), (6,0), (81,32), (85,32), (82,0)
rename1.abc
#< (78,8), (3,0), (4,20), (6,0), (81,32), (82,0)
#< (78,8), (3,0), (4,20), (6,0), (81,32), (85,32), (82,0)
from import_tree.rename1 import abc
abc
#< (75, 24),
#< 20 (1,0), (4,5), (75,24), (78,0), (81,17), (85,17), (88,17)
from import_tree.rename1 import abc
#< (88, 32),
from import_tree.rename1 import not_existing