mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-08 14:54:47 +08:00
search_call_signature refactoring
This commit is contained in:
@@ -33,6 +33,7 @@ from jedi.evaluate import compiled
|
|||||||
from jedi.evaluate import imports
|
from jedi.evaluate import imports
|
||||||
from jedi.evaluate.helpers import FakeName
|
from jedi.evaluate.helpers import FakeName
|
||||||
from jedi.evaluate.finder import get_names_of_scope
|
from jedi.evaluate.finder import get_names_of_scope
|
||||||
|
from jedi.evaluate.helpers import search_call_signatures
|
||||||
|
|
||||||
|
|
||||||
class NotFoundError(Exception):
|
class NotFoundError(Exception):
|
||||||
@@ -370,7 +371,7 @@ class Script(object):
|
|||||||
else:
|
else:
|
||||||
# Fetch definition of callee, if there's no path otherwise.
|
# Fetch definition of callee, if there's no path otherwise.
|
||||||
if not goto_path:
|
if not goto_path:
|
||||||
(call, _) = helpers.func_call_and_param_index(user_stmt, self._pos)
|
(call, _) = search_call_signatures(user_stmt, self._pos)
|
||||||
if call is not None:
|
if call is not None:
|
||||||
while call.next is not None:
|
while call.next is not None:
|
||||||
call = call.next
|
call = call.next
|
||||||
@@ -548,7 +549,7 @@ class Script(object):
|
|||||||
:rtype: list of :class:`classes.CallSignature`
|
:rtype: list of :class:`classes.CallSignature`
|
||||||
"""
|
"""
|
||||||
user_stmt = self._parser.user_stmt_with_whitespace()
|
user_stmt = self._parser.user_stmt_with_whitespace()
|
||||||
call, index = helpers.func_call_and_param_index(user_stmt, self._pos)
|
call, index = search_call_signatures(user_stmt, self._pos)
|
||||||
if call is None:
|
if call is None:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|||||||
@@ -9,16 +9,6 @@ from jedi.evaluate import imports
|
|||||||
from jedi.parser import representation as pr
|
from jedi.parser import representation as pr
|
||||||
|
|
||||||
|
|
||||||
def func_call_and_param_index(user_stmt, position):
|
|
||||||
debug.speed('func_call start')
|
|
||||||
call, index = None, 0
|
|
||||||
if call is None:
|
|
||||||
if user_stmt is not None and isinstance(user_stmt, pr.Statement):
|
|
||||||
call, index, _ = helpers.search_call_signatures(user_stmt, position)
|
|
||||||
debug.speed('func_call parsed')
|
|
||||||
return call, index
|
|
||||||
|
|
||||||
|
|
||||||
def completion_parts(path_until_cursor):
|
def completion_parts(path_until_cursor):
|
||||||
"""
|
"""
|
||||||
Returns the parts for the completion
|
Returns the parts for the completion
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import copy
|
|||||||
|
|
||||||
from jedi import common
|
from jedi import common
|
||||||
from jedi.parser import representation as pr
|
from jedi.parser import representation as pr
|
||||||
|
from jedi import debug
|
||||||
|
|
||||||
|
|
||||||
def fast_parent_copy(obj):
|
def fast_parent_copy(obj):
|
||||||
@@ -112,22 +113,28 @@ def array_for_pos(stmt, pos):
|
|||||||
return None, 0
|
return None, 0
|
||||||
|
|
||||||
|
|
||||||
def search_call_signatures(stmt, pos):
|
def search_call_signatures(user_stmt, position):
|
||||||
"""
|
"""
|
||||||
Returns the function Call that matches the position before.
|
Returns the function Call that matches the position before.
|
||||||
"""
|
"""
|
||||||
# some parts will of the statement will be removed
|
debug.speed('func_call start')
|
||||||
stmt = fast_parent_copy(stmt)
|
call, index = None, 0
|
||||||
arr, index = array_for_pos(stmt, pos)
|
if user_stmt is not None and isinstance(user_stmt, pr.Statement):
|
||||||
if arr is not None:
|
# some parts will of the statement will be removed
|
||||||
call = arr.parent
|
user_stmt = fast_parent_copy(user_stmt)
|
||||||
while isinstance(call.parent, pr.StatementElement):
|
arr, index = array_for_pos(user_stmt, position)
|
||||||
# Go to parent literal/variable until not possible anymore. This
|
if arr is not None:
|
||||||
# makes it possible to return the whole expression.
|
call = arr.parent
|
||||||
call = call.parent
|
while isinstance(call.parent, pr.StatementElement):
|
||||||
arr.parent.execution = None
|
# Go to parent literal/variable until not possible anymore. This
|
||||||
return call if isinstance(call, pr.Call) else None, index, False
|
# makes it possible to return the whole expression.
|
||||||
return None, 0, False
|
call = call.parent
|
||||||
|
arr.parent.execution = None
|
||||||
|
if not isinstance(call, pr.Call):
|
||||||
|
call = None
|
||||||
|
|
||||||
|
debug.speed('func_call parsed')
|
||||||
|
return call, index
|
||||||
|
|
||||||
|
|
||||||
def scan_statement_for_calls(stmt, search_name, assignment_details=False):
|
def scan_statement_for_calls(stmt, search_name, assignment_details=False):
|
||||||
|
|||||||
Reference in New Issue
Block a user