mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 14:04:26 +08:00
Added completions test with fuzzy=True
This commit is contained in:
@@ -201,7 +201,7 @@ class Script(object):
|
||||
self._inference_state.environment,
|
||||
)
|
||||
|
||||
def completions(self):
|
||||
def completions(self, fuzzy=False):
|
||||
"""
|
||||
Return :class:`classes.Completion` objects. Those objects contain
|
||||
information about the completions, more than just names.
|
||||
@@ -214,7 +214,7 @@ class Script(object):
|
||||
self._inference_state, self._get_module_context(), self._code_lines,
|
||||
self._pos, self.call_signatures
|
||||
)
|
||||
return completion.completions()
|
||||
return completion.completions(fuzzy)
|
||||
|
||||
def goto_definitions(self, **kwargs):
|
||||
"""
|
||||
|
||||
@@ -85,7 +85,7 @@ def get_flow_scope_node(module_node, position):
|
||||
|
||||
class Completion:
|
||||
def __init__(self, inference_state, module_context, code_lines, position,
|
||||
call_signatures_callback):
|
||||
call_signatures_callback, fuzzy=False):
|
||||
self._inference_state = inference_state
|
||||
self._module_context = module_context
|
||||
self._module_node = module_context.tree_node
|
||||
@@ -99,10 +99,12 @@ class Completion:
|
||||
self._position = position[0], position[1] - len(self._like_name)
|
||||
self._call_signatures_callback = call_signatures_callback
|
||||
|
||||
def completions(self, **kwargs):
|
||||
return self._completions(**kwargs)
|
||||
self._fuzzy = fuzzy
|
||||
|
||||
def _completions(self, fuzzy=False):
|
||||
def completions(self, fuzzy=False, **kwargs):
|
||||
return self._completions(fuzzy, **kwargs)
|
||||
|
||||
def _completions(self, fuzzy):
|
||||
leaf = self._module_node.get_leaf_for_position(self._position, include_prefixes=True)
|
||||
string, start_leaf = _extract_string_while_in_string(leaf, self._position)
|
||||
if string is not None:
|
||||
|
||||
@@ -304,3 +304,10 @@ def test_goto_follow_builtin_imports(Script):
|
||||
assert d.in_builtin_module() is True
|
||||
d, = s.goto_assignments(follow_imports=True, follow_builtin_imports=True)
|
||||
assert d.in_builtin_module() is True
|
||||
|
||||
|
||||
def test_fuzzy_completion(Script):
|
||||
script = Script('string = "hello"\nstring.upper')
|
||||
assert ['isupper', 'upper'] == [comp.name
|
||||
for comp in
|
||||
script.completions(fuzzy=True)]
|
||||
|
||||
Reference in New Issue
Block a user