forked from VimPlug/jedi
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:
|
except IndexError:
|
||||||
definitions = []
|
definitions = []
|
||||||
search_name = str(name_part)
|
search_name = str(name_part)
|
||||||
|
|
||||||
if add_import_name:
|
if add_import_name:
|
||||||
import_name = self.parser.user_stmt.get_defined_names()
|
import_name = self.parser.user_stmt.get_defined_names()
|
||||||
# imports have only one name
|
# imports have only one name
|
||||||
@@ -328,7 +329,10 @@ class Script(object):
|
|||||||
TODO implement additional_module_paths
|
TODO implement additional_module_paths
|
||||||
"""
|
"""
|
||||||
definitions, search_name = self._goto(add_import_name=True)
|
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 = set([d.get_parent_until() for d in definitions])
|
||||||
module.add(self.parser.module)
|
module.add(self.parser.module)
|
||||||
@@ -418,15 +422,14 @@ class Script(object):
|
|||||||
def _get_on_import_stmt(self, is_like_search=False):
|
def _get_on_import_stmt(self, is_like_search=False):
|
||||||
user_stmt = self.parser.user_stmt
|
user_stmt = self.parser.user_stmt
|
||||||
import_names = user_stmt.get_all_import_names()
|
import_names = user_stmt.get_all_import_names()
|
||||||
count = 0
|
|
||||||
kill_count = -1
|
kill_count = -1
|
||||||
cur_name_part = None
|
cur_name_part = None
|
||||||
for i in import_names:
|
for i in import_names:
|
||||||
for name_part in i.names:
|
for name_part in i.names:
|
||||||
count += 1
|
if name_part.end_pos >= self.pos:
|
||||||
if self.pos <= name_part.end_pos:
|
if not cur_name_part:
|
||||||
|
cur_name_part = name_part
|
||||||
kill_count += 1
|
kill_count += 1
|
||||||
cur_name_part = name_part
|
|
||||||
|
|
||||||
i = imports.ImportPath(user_stmt, is_like_search,
|
i = imports.ImportPath(user_stmt, is_like_search,
|
||||||
kill_count=kill_count, direct_resolve=True)
|
kill_count=kill_count, direct_resolve=True)
|
||||||
|
|||||||
@@ -348,7 +348,7 @@ def related_names(definitions, search_name, mods):
|
|||||||
|
|
||||||
for f in follow:
|
for f in follow:
|
||||||
follow_res, search = evaluate.goto(call.parent_stmt(), f)
|
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]
|
#print follow_res, [d.parent() for d in follow_res]
|
||||||
# compare to see if they match
|
# compare to see if they match
|
||||||
@@ -381,9 +381,9 @@ def related_names(definitions, search_name, mods):
|
|||||||
if name_part == search_name:
|
if name_part == search_name:
|
||||||
imps.append((count, name_part))
|
imps.append((count, name_part))
|
||||||
|
|
||||||
for kill_count, name_part in imps:
|
for used_count, name_part in imps:
|
||||||
i = imports.ImportPath(stmt, False,
|
i = imports.ImportPath(stmt, kill_count=count - used_count,
|
||||||
kill_count=count - kill_count, direct_resolve=True)
|
direct_resolve=True)
|
||||||
f = i.follow(is_goto=True)
|
f = i.follow(is_goto=True)
|
||||||
if set(f) & set(definitions):
|
if set(f) & set(definitions):
|
||||||
names.append(RelatedName(name_part, stmt))
|
names.append(RelatedName(name_part, stmt))
|
||||||
@@ -393,13 +393,12 @@ def related_names(definitions, search_name, mods):
|
|||||||
names += check_call(call)
|
names += check_call(call)
|
||||||
return names
|
return names
|
||||||
|
|
||||||
def related_name_add_import_modules(definitions):
|
def related_name_add_import_modules(definitions, search_name):
|
||||||
""" Adds the modules of the imports """
|
""" Adds the modules of the imports """
|
||||||
new = set()
|
new = set()
|
||||||
for d in definitions:
|
for d in definitions:
|
||||||
if isinstance(d.parent(), parsing.Import):
|
if isinstance(d.parent(), parsing.Import):
|
||||||
# TODO introduce kill_count for not fully used imports
|
s = imports.ImportPath(d.parent(), direct_resolve=True)
|
||||||
s = imports.ImportPath(d.parent(), False, direct_resolve=True)
|
|
||||||
try:
|
try:
|
||||||
new.add(s.follow(is_goto=True)[0])
|
new.add(s.follow(is_goto=True)[0])
|
||||||
except IndexError:
|
except IndexError:
|
||||||
|
|||||||
@@ -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
|
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
|
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
|
from import_tree.rename1 import abc
|
||||||
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
|
from import_tree.rename1 import not_existing
|
||||||
|
|||||||
Reference in New Issue
Block a user