mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 14:04:26 +08:00
Completions.complete returns None for fuzzy completions #1409
This commit is contained in:
@@ -408,11 +408,12 @@ class Completion(BaseDefinition):
|
|||||||
`Completion` objects are returned from :meth:`api.Script.completions`. They
|
`Completion` objects are returned from :meth:`api.Script.completions`. They
|
||||||
provide additional information about a completion.
|
provide additional information about a completion.
|
||||||
"""
|
"""
|
||||||
def __init__(self, inference_state, name, stack, like_name_length):
|
def __init__(self, inference_state, name, stack, like_name_length, is_fuzzy):
|
||||||
super(Completion, self).__init__(inference_state, name)
|
super(Completion, self).__init__(inference_state, name)
|
||||||
|
|
||||||
self._like_name_length = like_name_length
|
self._like_name_length = like_name_length
|
||||||
self._stack = stack
|
self._stack = stack
|
||||||
|
self._is_fuzzy = is_fuzzy
|
||||||
|
|
||||||
# Completion objects with the same Completion name (which means
|
# Completion objects with the same Completion name (which means
|
||||||
# duplicate items in the completion)
|
# duplicate items in the completion)
|
||||||
@@ -438,6 +439,9 @@ class Completion(BaseDefinition):
|
|||||||
@property
|
@property
|
||||||
def complete(self):
|
def complete(self):
|
||||||
"""
|
"""
|
||||||
|
Only works with non-fuzzy completions. Returns None if fuzzy
|
||||||
|
completions are used.
|
||||||
|
|
||||||
Return the rest of the word, e.g. completing ``isinstance``::
|
Return the rest of the word, e.g. completing ``isinstance``::
|
||||||
|
|
||||||
isinstan# <-- Cursor is here
|
isinstan# <-- Cursor is here
|
||||||
@@ -452,9 +456,9 @@ class Completion(BaseDefinition):
|
|||||||
|
|
||||||
completing ``foo(par`` would give a ``Completion`` which `complete`
|
completing ``foo(par`` would give a ``Completion`` which `complete`
|
||||||
would be `am=`
|
would be `am=`
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
if self._is_fuzzy:
|
||||||
|
return None
|
||||||
return self._complete(True)
|
return self._complete(True)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|||||||
@@ -45,7 +45,8 @@ def filter_names(inference_state, completion_names, stack, like_name, fuzzy):
|
|||||||
inference_state,
|
inference_state,
|
||||||
name,
|
name,
|
||||||
stack,
|
stack,
|
||||||
len(like_name)
|
len(like_name),
|
||||||
|
is_fuzzy=fuzzy,
|
||||||
)
|
)
|
||||||
k = (new.name, new.complete) # key
|
k = (new.name, new.complete) # key
|
||||||
if k in comp_dct and settings.no_completion_duplicates:
|
if k in comp_dct and settings.no_completion_duplicates:
|
||||||
|
|||||||
@@ -62,7 +62,8 @@ def file_name_completions(inference_state, module_context, start_leaf, string,
|
|||||||
inference_state,
|
inference_state,
|
||||||
FileName(inference_state, name[len(must_start_with) - like_name_length:]),
|
FileName(inference_state, name[len(must_start_with) - like_name_length:]),
|
||||||
stack=None,
|
stack=None,
|
||||||
like_name_length=like_name_length
|
like_name_length=like_name_length,
|
||||||
|
is_fuzzy=fuzzy,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -331,7 +331,10 @@ def test_math_fuzzy_completion(Script, environment):
|
|||||||
expected = ['copysign', 'log', 'log10', 'log1p']
|
expected = ['copysign', 'log', 'log10', 'log1p']
|
||||||
if environment.version_info.major >= 3:
|
if environment.version_info.major >= 3:
|
||||||
expected.append('log2')
|
expected.append('log2')
|
||||||
assert expected == [comp.name for comp in script.completions(fuzzy=True)]
|
completions = script.completions(fuzzy=True)
|
||||||
|
assert expected == [comp.name for comp in completions]
|
||||||
|
for c in completions:
|
||||||
|
assert c.complete is None
|
||||||
|
|
||||||
|
|
||||||
def test_file_fuzzy_completion(Script):
|
def test_file_fuzzy_completion(Script):
|
||||||
|
|||||||
Reference in New Issue
Block a user