forked from VimPlug/jedi
Switched to fuzzy boolean
This commit is contained in:
@@ -31,10 +31,6 @@ def start_match(string, like_name):
|
|||||||
return string.startswith(like_name)
|
return string.startswith(like_name)
|
||||||
|
|
||||||
|
|
||||||
def substr_match(string, like_name):
|
|
||||||
return like_name in string
|
|
||||||
|
|
||||||
|
|
||||||
def fuzzy_match(string, like_name):
|
def fuzzy_match(string, like_name):
|
||||||
if len(like_name) <= 1:
|
if len(like_name) <= 1:
|
||||||
return like_name in string
|
return like_name in string
|
||||||
@@ -44,7 +40,7 @@ def fuzzy_match(string, like_name):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def filter_names(inference_state, completion_names, stack, like_name, match_method):
|
def filter_names(inference_state, completion_names, stack, like_name, fuzzy):
|
||||||
comp_dct = {}
|
comp_dct = {}
|
||||||
if settings.case_insensitive_completion:
|
if settings.case_insensitive_completion:
|
||||||
like_name = like_name.lower()
|
like_name = like_name.lower()
|
||||||
@@ -52,8 +48,11 @@ def filter_names(inference_state, completion_names, stack, like_name, match_meth
|
|||||||
string = name.string_name
|
string = name.string_name
|
||||||
if settings.case_insensitive_completion:
|
if settings.case_insensitive_completion:
|
||||||
string = string.lower()
|
string = string.lower()
|
||||||
|
if fuzzy:
|
||||||
if match_method(string, like_name):
|
match = fuzzy_match(string, like_name)
|
||||||
|
else:
|
||||||
|
match = start_match(string, like_name)
|
||||||
|
if match:
|
||||||
new = classes.Completion(
|
new = classes.Completion(
|
||||||
inference_state,
|
inference_state,
|
||||||
name,
|
name,
|
||||||
@@ -103,7 +102,7 @@ class Completion:
|
|||||||
def completions(self, **kwargs):
|
def completions(self, **kwargs):
|
||||||
return self._completions(**kwargs)
|
return self._completions(**kwargs)
|
||||||
|
|
||||||
def _completions(self, method=start_match):
|
def _completions(self, fuzzy=False):
|
||||||
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:
|
||||||
@@ -118,7 +117,7 @@ class Completion:
|
|||||||
completion_names = self._get_value_completions(leaf)
|
completion_names = self._get_value_completions(leaf)
|
||||||
|
|
||||||
completions = filter_names(self._inference_state, completion_names,
|
completions = filter_names(self._inference_state, completion_names,
|
||||||
self.stack, self._like_name, method)
|
self.stack, self._like_name, fuzzy)
|
||||||
|
|
||||||
return sorted(completions, key=lambda x: (x.name.startswith('__'),
|
return sorted(completions, key=lambda x: (x.name.startswith('__'),
|
||||||
x.name.startswith('_'),
|
x.name.startswith('_'),
|
||||||
|
|||||||
@@ -268,14 +268,11 @@ def test_file_path_completions(Script, file, code, column, expected):
|
|||||||
else:
|
else:
|
||||||
assert [c.complete for c in comps] == expected
|
assert [c.complete for c in comps] == expected
|
||||||
|
|
||||||
from jedi.api.completion import start_match, substr_match, fuzzy_match
|
from jedi.api.completion import start_match, fuzzy_match
|
||||||
|
|
||||||
def test_start_match():
|
def test_start_match():
|
||||||
assert start_match('Condition', 'C')
|
assert start_match('Condition', 'C')
|
||||||
|
|
||||||
def test_substr_match():
|
|
||||||
assert substr_match('Condition', 'dit')
|
|
||||||
|
|
||||||
def test_fuzzy_match():
|
def test_fuzzy_match():
|
||||||
assert fuzzy_match('Condition', 'i')
|
assert fuzzy_match('Condition', 'i')
|
||||||
assert not fuzzy_match('Condition', 'p')
|
assert not fuzzy_match('Condition', 'p')
|
||||||
|
|||||||
Reference in New Issue
Block a user