mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 22:14:27 +08:00
Merge pull request #1704 from infokiller/expose-comp-prefix-len
add Completion.get_completion_prefix_length
This commit is contained in:
@@ -749,6 +749,24 @@ class Completion(BaseName):
|
|||||||
|
|
||||||
return super().type
|
return super().type
|
||||||
|
|
||||||
|
def get_completion_prefix_length(self):
|
||||||
|
"""
|
||||||
|
Returns the length of the prefix being completed.
|
||||||
|
For example, completing ``isinstance``::
|
||||||
|
|
||||||
|
isinstan# <-- Cursor is here
|
||||||
|
|
||||||
|
would return 8, because len('isinstan') == 8.
|
||||||
|
|
||||||
|
Assuming the following function definition::
|
||||||
|
|
||||||
|
def foo(param=0):
|
||||||
|
pass
|
||||||
|
|
||||||
|
completing ``foo(par`` would return 3.
|
||||||
|
"""
|
||||||
|
return self._like_name_length
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<%s: %s>' % (type(self).__name__, self._name.get_public_name())
|
return '<%s: %s>' % (type(self).__name__, self._name.get_public_name())
|
||||||
|
|
||||||
|
|||||||
@@ -513,10 +513,14 @@ def test_added_equals_to_params(Script):
|
|||||||
|
|
||||||
assert run('foo(bar').name_with_symbols == 'bar='
|
assert run('foo(bar').name_with_symbols == 'bar='
|
||||||
assert run('foo(bar').complete == '='
|
assert run('foo(bar').complete == '='
|
||||||
|
assert run('foo(bar').get_completion_prefix_length() == 3
|
||||||
assert run('foo(bar, baz').complete == '='
|
assert run('foo(bar, baz').complete == '='
|
||||||
|
assert run('foo(bar, baz').get_completion_prefix_length() == 3
|
||||||
assert run(' bar').name_with_symbols == 'bar'
|
assert run(' bar').name_with_symbols == 'bar'
|
||||||
assert run(' bar').complete == ''
|
assert run(' bar').complete == ''
|
||||||
|
assert run(' bar').get_completion_prefix_length() == 3
|
||||||
x = run('foo(bar=isins').name_with_symbols
|
x = run('foo(bar=isins').name_with_symbols
|
||||||
|
assert run('foo(bar=isins').get_completion_prefix_length() == 5
|
||||||
assert x == 'isinstance'
|
assert x == 'isinstance'
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user