Added completions test with fuzzy=True

This commit is contained in:
Johannes Maria Frank
2019-10-04 17:18:01 +01:00
parent 85278242c3
commit 0b56bf8f08
3 changed files with 15 additions and 6 deletions

View File

@@ -201,7 +201,7 @@ class Script(object):
self._inference_state.environment, self._inference_state.environment,
) )
def completions(self): def completions(self, fuzzy=False):
""" """
Return :class:`classes.Completion` objects. Those objects contain Return :class:`classes.Completion` objects. Those objects contain
information about the completions, more than just names. 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._inference_state, self._get_module_context(), self._code_lines,
self._pos, self.call_signatures self._pos, self.call_signatures
) )
return completion.completions() return completion.completions(fuzzy)
def goto_definitions(self, **kwargs): def goto_definitions(self, **kwargs):
""" """

View File

@@ -85,7 +85,7 @@ def get_flow_scope_node(module_node, position):
class Completion: class Completion:
def __init__(self, inference_state, module_context, code_lines, position, def __init__(self, inference_state, module_context, code_lines, position,
call_signatures_callback): call_signatures_callback, fuzzy=False):
self._inference_state = inference_state self._inference_state = inference_state
self._module_context = module_context self._module_context = module_context
self._module_node = module_context.tree_node self._module_node = module_context.tree_node
@@ -99,10 +99,12 @@ class Completion:
self._position = position[0], position[1] - len(self._like_name) self._position = position[0], position[1] - len(self._like_name)
self._call_signatures_callback = call_signatures_callback self._call_signatures_callback = call_signatures_callback
def completions(self, **kwargs): self._fuzzy = fuzzy
return self._completions(**kwargs)
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) leaf = self._module_node.get_leaf_for_position(self._position, include_prefixes=True)
string, start_leaf = _extract_string_while_in_string(leaf, self._position) string, start_leaf = _extract_string_while_in_string(leaf, self._position)
if string is not None: if string is not None:

View File

@@ -304,3 +304,10 @@ def test_goto_follow_builtin_imports(Script):
assert d.in_builtin_module() is True assert d.in_builtin_module() is True
d, = s.goto_assignments(follow_imports=True, follow_builtin_imports=True) d, = s.goto_assignments(follow_imports=True, follow_builtin_imports=True)
assert d.in_builtin_module() is 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)]