1
0
forked from VimPlug/jedi

Even more refactorings

This commit is contained in:
Dave Halter
2019-07-05 15:24:39 -07:00
parent 76c6104415
commit d579c0ad57
3 changed files with 21 additions and 15 deletions

View File

@@ -365,8 +365,7 @@ class Script(object):
:rtype: list of :class:`classes.CallSignature`
"""
call_details = \
helpers.get_call_signature_details(self._module_node, self._pos)
call_details = helpers.get_call_signature_details(self._module_node, self._pos)
if call_details is None:
return []

View File

@@ -626,7 +626,7 @@ class CallSignature(Definition):
return i
return None
if self._call_details.call_index >= len(self.params):
if self._call_details.index >= len(self.params):
for i, param in enumerate(self.params):
tree_name = param._name.tree_name
if tree_name is not None:
@@ -634,7 +634,7 @@ class CallSignature(Definition):
if tree_name.get_definition().star_count == 1:
return i
return None
return self._call_details.call_index
return self._call_details.index
@property
def params(self):
@@ -657,7 +657,7 @@ class CallSignature(Definition):
return '<%s: %s index=%r params=[%s]>' % (
type(self).__name__,
self._name.string_name,
self._index,
self.index,
self._params_str,
)

View File

@@ -159,10 +159,20 @@ def evaluate_goto_definition(evaluator, context, leaf):
return definitions
CallDetails = namedtuple(
'CallDetails',
['bracket_leaf', 'call_index', 'keyword_name_str']
)
class CallDetails(object):
def __init__(self, bracket_leaf, children, position):
['bracket_leaf', 'call_index', 'keyword_name_str']
self.bracket_leaf = bracket_leaf
self._children = children
self._position = position
@property
def index(self):
return _get_index_and_key(self._children, self._position)[0]
@property
def keyword_name_str(self):
return _get_index_and_key(self._children, self._position)[1]
def _get_index_and_key(nodes, position):
@@ -198,10 +208,7 @@ def _get_call_signature_details_from_error_node(node, position):
if name is None:
continue
if name.type == 'name' or name.parent.type in ('trailer', 'atom'):
return CallDetails(
element,
*_get_index_and_key(children, position)
)
return CallDetails(element, children, position)
def get_call_signature_details(module, position):
@@ -213,6 +220,7 @@ def get_call_signature_details(module, position):
return None
if leaf == ')':
# TODO is this ok?
if leaf.end_pos == position:
leaf = leaf.get_next_leaf()
@@ -235,8 +243,7 @@ def get_call_signature_details(module, position):
leaf = node.get_previous_leaf()
if leaf is None:
return None
return CallDetails(
node.children[0], *_get_index_and_key(node.children, position))
return CallDetails(node.children[0], node.children, position)
node = node.parent