From ccdf7eddf461db1d78b34391d92e0f3c234d645e Mon Sep 17 00:00:00 2001 From: Yoni Weill Date: Sat, 5 Dec 2020 21:11:32 +0200 Subject: [PATCH 1/2] add Completion.get_completion_prefix_length fixes #1687 --- jedi/api/classes.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/jedi/api/classes.py b/jedi/api/classes.py index a8d9fb19..42aac726 100644 --- a/jedi/api/classes.py +++ b/jedi/api/classes.py @@ -749,6 +749,24 @@ class Completion(BaseName): 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): return '<%s: %s>' % (type(self).__name__, self._name.get_public_name()) From 10958200060a546d5ed8250809fee5ae7e94ae0f Mon Sep 17 00:00:00 2001 From: Yoni Weill Date: Sun, 6 Dec 2020 21:09:03 +0200 Subject: [PATCH 2/2] add tests for get_completion_prefix_length --- test/test_api/test_classes.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/test_api/test_classes.py b/test/test_api/test_classes.py index 6add83f6..4a6f7323 100644 --- a/test/test_api/test_classes.py +++ b/test/test_api/test_classes.py @@ -513,10 +513,14 @@ def test_added_equals_to_params(Script): assert run('foo(bar').name_with_symbols == 'bar=' 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').get_completion_prefix_length() == 3 assert run(' bar').name_with_symbols == 'bar' assert run(' bar').complete == '' + assert run(' bar').get_completion_prefix_length() == 3 x = run('foo(bar=isins').name_with_symbols + assert run('foo(bar=isins').get_completion_prefix_length() == 5 assert x == 'isinstance'