forked from VimPlug/jedi
again working with further refactorings
This commit is contained in:
31
jedi/api.py
31
jedi/api.py
@@ -299,12 +299,19 @@ class Script(object):
|
|||||||
return sorted(d, key=lambda x: (x.module_path, x.start_pos))
|
return sorted(d, key=lambda x: (x.module_path, x.start_pos))
|
||||||
|
|
||||||
def goto(self):
|
def goto(self):
|
||||||
|
""" TODO doc """
|
||||||
|
d = [Definition(d) for d in set(self._goto()[0])]
|
||||||
|
return sorted(d, key=lambda x: (x.module_path, x.start_pos))
|
||||||
|
|
||||||
|
def _goto(self, check_imports=True):
|
||||||
user_stmt = self.parser.user_stmt
|
user_stmt = self.parser.user_stmt
|
||||||
goto_path = self.module.get_path_under_cursor()
|
goto_path = self.module.get_path_under_cursor()
|
||||||
context = self.module.get_context()
|
context = self.module.get_context()
|
||||||
if next(context) in ('class', 'def'):
|
if next(context) in ('class', 'def'):
|
||||||
definitions = set([self.module.parser.user_scope])
|
user_scope = self.parser.user_scope
|
||||||
elif isinstance(self.parser.user_stmt, parsing.Import):
|
definitions = set([user_scope.name])
|
||||||
|
search_name = str(user_scope.name)
|
||||||
|
elif check_imports and isinstance(self.parser.user_stmt, parsing.Import):
|
||||||
import_names = user_stmt.get_all_import_names()
|
import_names = user_stmt.get_all_import_names()
|
||||||
count = 0
|
count = 0
|
||||||
kill_count = -1
|
kill_count = -1
|
||||||
@@ -319,12 +326,11 @@ class Script(object):
|
|||||||
definitions = [s.follow(is_goto=True)[0]]
|
definitions = [s.follow(is_goto=True)[0]]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
definitions = []
|
definitions = []
|
||||||
|
search_name = str(import_names[-1])
|
||||||
else:
|
else:
|
||||||
stmt = self._get_under_cursor_stmt(goto_path)
|
stmt = self._get_under_cursor_stmt(goto_path)
|
||||||
definitions, search_name = evaluate.goto(stmt)
|
definitions, search_name = evaluate.goto(stmt)
|
||||||
|
return definitions, search_name
|
||||||
d = [Definition(d) for d in set(definitions)]
|
|
||||||
return sorted(d, key=lambda x: (x.module_path, x.start_pos))
|
|
||||||
|
|
||||||
def related_names(self):
|
def related_names(self):
|
||||||
"""
|
"""
|
||||||
@@ -333,21 +339,10 @@ class Script(object):
|
|||||||
This function can be used either to show all the usages of a variable
|
This function can be used either to show all the usages of a variable
|
||||||
or for renaming purposes.
|
or for renaming purposes.
|
||||||
"""
|
"""
|
||||||
goto_path = self.module.get_path_under_cursor()
|
definitions, search_name = self._goto(check_imports=False)
|
||||||
context = self.module.get_context()
|
|
||||||
if next(context) in ('class', 'def'):
|
|
||||||
if isinstance(self.module.parser.user_scope, parsing.Function):
|
|
||||||
e = evaluate.Function(self.module.parser.user_scope)
|
|
||||||
else:
|
|
||||||
e = evaluate.Class(self.module.parser.user_scope)
|
|
||||||
definitions = [e.name]
|
|
||||||
search_name = str(e.name)
|
|
||||||
else:
|
|
||||||
stmt = self._get_under_cursor_stmt(goto_path)
|
|
||||||
definitions, search_name = evaluate.goto(stmt)
|
|
||||||
|
|
||||||
module = set([d.get_parent_until() for d in definitions])
|
module = set([d.get_parent_until() for d in definitions])
|
||||||
module.add(self.module.parser.module)
|
module.add(self.parser.module)
|
||||||
if definitions:
|
if definitions:
|
||||||
names = dynamic.related_names(definitions, search_name, module)
|
names = dynamic.related_names(definitions, search_name, module)
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -288,7 +288,7 @@ class Module(Scope):
|
|||||||
n += self.global_vars
|
n += self.global_vars
|
||||||
return n
|
return n
|
||||||
|
|
||||||
def get_module_name(self):
|
def get_name(self):
|
||||||
""" This is used for the goto function. """
|
""" This is used for the goto function. """
|
||||||
sep = (os.path.sep,) * 2
|
sep = (os.path.sep,) * 2
|
||||||
r = re.search(r'([^%s]+?)(%s__init__)?(\.py)?$' % sep, self.path)
|
r = re.search(r'([^%s]+?)(%s__init__)?(\.py)?$' % sep, self.path)
|
||||||
|
|||||||
Reference in New Issue
Block a user