mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-09 07:14:48 +08:00
Fix and test CallSignature.bracket_start.
This commit is contained in:
@@ -290,7 +290,7 @@ class Script(object):
|
|||||||
return scopes
|
return scopes
|
||||||
|
|
||||||
@memoize_default()
|
@memoize_default()
|
||||||
def _get_under_cursor_stmt(self, cursor_txt):
|
def _get_under_cursor_stmt(self, cursor_txt, start_pos=None):
|
||||||
tokenizer = source_tokens(cursor_txt)
|
tokenizer = source_tokens(cursor_txt)
|
||||||
r = Parser(self._grammar, cursor_txt, tokenizer=tokenizer)
|
r = Parser(self._grammar, cursor_txt, tokenizer=tokenizer)
|
||||||
try:
|
try:
|
||||||
@@ -301,9 +301,10 @@ class Script(object):
|
|||||||
|
|
||||||
user_stmt = self._parser.user_stmt()
|
user_stmt = self._parser.user_stmt()
|
||||||
if user_stmt is None:
|
if user_stmt is None:
|
||||||
# Set the start_pos to a pseudo position, that doesn't exist but works
|
# Set the start_pos to a pseudo position, that doesn't exist but
|
||||||
# perfectly well (for both completions in docstrings and statements).
|
# works perfectly well (for both completions in docstrings and
|
||||||
pos = self._pos
|
# statements).
|
||||||
|
pos = start_pos or self._pos
|
||||||
else:
|
else:
|
||||||
pos = user_stmt.start_pos
|
pos = user_stmt.start_pos
|
||||||
|
|
||||||
@@ -500,11 +501,11 @@ class Script(object):
|
|||||||
|
|
||||||
:rtype: list of :class:`classes.CallSignature`
|
:rtype: list of :class:`classes.CallSignature`
|
||||||
"""
|
"""
|
||||||
call_txt, call_index, key_name = self._user_context.call_signature()
|
call_txt, call_index, key_name, start_pos = self._user_context.call_signature()
|
||||||
if call_txt is None:
|
if call_txt is None:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
stmt = self._get_under_cursor_stmt(call_txt)
|
stmt = self._get_under_cursor_stmt(call_txt, start_pos)
|
||||||
if stmt is None:
|
if stmt is None:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|||||||
@@ -613,11 +613,11 @@ class CallSignature(Definition):
|
|||||||
It knows what functions you are currently in. e.g. `isinstance(` would
|
It knows what functions you are currently in. e.g. `isinstance(` would
|
||||||
return the `isinstance` function. without `(` it would return nothing.
|
return the `isinstance` function. without `(` it would return nothing.
|
||||||
"""
|
"""
|
||||||
def __init__(self, evaluator, executable_name, call, index, key_name):
|
def __init__(self, evaluator, executable_name, call_stmt, index, key_name):
|
||||||
super(CallSignature, self).__init__(evaluator, executable_name)
|
super(CallSignature, self).__init__(evaluator, executable_name)
|
||||||
self._index = index
|
self._index = index
|
||||||
self._key_name = key_name
|
self._key_name = key_name
|
||||||
self._call = call
|
self._call_stmt = call_stmt
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def index(self):
|
def index(self):
|
||||||
@@ -649,10 +649,7 @@ class CallSignature(Definition):
|
|||||||
The indent of the bracket that is responsible for the last function
|
The indent of the bracket that is responsible for the last function
|
||||||
call.
|
call.
|
||||||
"""
|
"""
|
||||||
c = self._call
|
return self._call_stmt.end_pos
|
||||||
while c.next is not None:
|
|
||||||
c = c.next
|
|
||||||
return c.name.end_pos
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def call_name(self):
|
def call_name(self):
|
||||||
|
|||||||
@@ -187,8 +187,8 @@ class UserContext(object):
|
|||||||
elif next_must_be_name:
|
elif next_must_be_name:
|
||||||
if tok_type == tokenize.NAME:
|
if tok_type == tokenize.NAME:
|
||||||
end_pos = start_pos[0], start_pos[1] + len(tok_str)
|
end_pos = start_pos[0], start_pos[1] + len(tok_str)
|
||||||
call, _ = self._calc_path_until_cursor(start_pos=end_pos)
|
call, start_pos = self._calc_path_until_cursor(start_pos=end_pos)
|
||||||
return call, index, key_name
|
return call, index, key_name, start_pos
|
||||||
index = 0
|
index = 0
|
||||||
next_must_be_name = False
|
next_must_be_name = False
|
||||||
elif next_is_key:
|
elif next_is_key:
|
||||||
@@ -207,7 +207,7 @@ class UserContext(object):
|
|||||||
index += 1
|
index += 1
|
||||||
elif tok_str == '=':
|
elif tok_str == '=':
|
||||||
next_is_key = True
|
next_is_key = True
|
||||||
return None, 0, None
|
return None, 0, None, (0, 0)
|
||||||
|
|
||||||
def get_context(self, yield_positions=False):
|
def get_context(self, yield_positions=False):
|
||||||
self.get_path_until_cursor() # In case _start_cursor_pos is undefined.
|
self.get_path_until_cursor() # In case _start_cursor_pos is undefined.
|
||||||
|
|||||||
@@ -301,3 +301,12 @@ def test_signature_index():
|
|||||||
assert get(both + 'foo(a=2').index == 1
|
assert get(both + 'foo(a=2').index == 1
|
||||||
assert get(both + 'foo(a=2, b=2').index == 1
|
assert get(both + 'foo(a=2, b=2').index == 1
|
||||||
assert get(both + 'foo(a, b, c').index == 0
|
assert get(both + 'foo(a, b, c').index == 0
|
||||||
|
|
||||||
|
|
||||||
|
def test_bracket_start():
|
||||||
|
def bracket_start(src):
|
||||||
|
signatures = Script(src).call_signatures()
|
||||||
|
assert len(signatures) == 1
|
||||||
|
return signatures[0].bracket_start
|
||||||
|
|
||||||
|
assert bracket_start('str(') == (1, 3)
|
||||||
|
|||||||
Reference in New Issue
Block a user