Added experimental substring and fuzzysearch

This commit is contained in:
Johannes Maria Frank
2019-09-26 08:17:30 +01:00
parent a6fcf779d4
commit 8f306953da
2 changed files with 32 additions and 1 deletions

View File

@@ -27,6 +27,22 @@ def get_call_signature_param_names(call_signatures):
Parameter.KEYWORD_ONLY):
yield p._name
def start_match(string, like_name):
return string.startswith(like_name)
def substr_match(string, like_name):
return like_name in string
def fuzzy_match(string, like_name):
if len(like_name) <= 1:
return like_name in string
pos = string.find(like_name[0])
if pos >= 0:
return fuzzy_match(string[pos + 1:], like_name[1:])
return False
def filter_names(inference_state, completion_names, stack, like_name):
comp_dct = {}
@@ -37,7 +53,7 @@ def filter_names(inference_state, completion_names, stack, like_name):
if settings.case_insensitive_completion:
string = string.lower()
if string.startswith(like_name):
if fuzzy_match(string, like_name):
new = classes.Completion(
inference_state,
name,

View File

@@ -267,3 +267,18 @@ def test_file_path_completions(Script, file, code, column, expected):
assert len(comps) > 100 # This is basically global completions.
else:
assert [c.complete for c in comps] == expected
from jedi.api.completion import start_match, substr_match, fuzzy_match
def test_start_match():
assert start_match('Condition', 'C')
def test_substr_match():
assert substr_match('Condition', 'dit')
def test_fuzzy_match():
assert fuzzy_match('Condition', 'i')
assert not fuzzy_match('Condition', 'p')
assert fuzzy_match('Condition', 'ii')
assert not fuzzy_match('Condition', 'Ciito')
assert fuzzy_match('Condition', 'Cdiio')