mirror of
https://github.com/davidhalter/jedi.git
synced 2026-03-05 03:34:15 +08:00
Make Script.definition work inside function call
This commit is contained in:
33
jedi/api.py
33
jedi/api.py
@@ -231,13 +231,40 @@ class Script(object):
|
|||||||
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()
|
||||||
|
scopes = set()
|
||||||
|
lower_priority_operators = ('(', ',')
|
||||||
|
"""Operators that could hide callee."""
|
||||||
if next(context) in ('class', 'def'):
|
if next(context) in ('class', 'def'):
|
||||||
scopes = set([self._module.parser.user_scope])
|
scopes = set([self._module.parser.user_scope])
|
||||||
elif not goto_path:
|
elif not goto_path:
|
||||||
op = self._module.get_operator_under_cursor()
|
op = self._module.get_operator_under_cursor()
|
||||||
scopes = set([keywords.get_operator(op, self.pos)] if op else [])
|
if op and op not in lower_priority_operators:
|
||||||
else:
|
scopes = set([keywords.get_operator(op, self.pos)])
|
||||||
scopes = set(self._prepare_goto(goto_path))
|
|
||||||
|
# Fetch definition of callee
|
||||||
|
if not goto_path:
|
||||||
|
try:
|
||||||
|
(call, _) = self._get_function_call_and_param_index_at_point()
|
||||||
|
except NotFoundError:
|
||||||
|
call = None
|
||||||
|
if call is not None:
|
||||||
|
while call.next is not None:
|
||||||
|
call = call.next
|
||||||
|
# reset cursor position:
|
||||||
|
(row, col) = call.name.end_pos
|
||||||
|
self.pos = (row, max(col - 1, 0))
|
||||||
|
self._module = modules.ModuleWithCursor(
|
||||||
|
self._source_path,
|
||||||
|
source=self.source,
|
||||||
|
position=self.pos)
|
||||||
|
# then try to find the path again
|
||||||
|
goto_path = self._module.get_path_under_cursor()
|
||||||
|
|
||||||
|
if not scopes:
|
||||||
|
if goto_path:
|
||||||
|
scopes = set(self._prepare_goto(goto_path))
|
||||||
|
elif op in lower_priority_operators:
|
||||||
|
scopes = set([keywords.get_operator(op, self.pos)])
|
||||||
|
|
||||||
scopes = resolve_import_paths(scopes)
|
scopes = resolve_import_paths(scopes)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user