mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 14:04:26 +08:00
Implement Script.complete_search instead of the complete param and return Completion objects
This commit is contained in:
@@ -344,16 +344,14 @@ class Script(object):
|
||||
|
||||
:param all_scopes: If True lists the symbols of all scopes instead of
|
||||
only the module.
|
||||
:param definitions: If True lists the names that have been defined by a
|
||||
class, function or a statement (``a = b`` returns ``a``).
|
||||
:param references: If True lists all the names that are not listed by
|
||||
``definitions=True``. E.g. ``a = b`` returns ``b``.
|
||||
"""
|
||||
return self._search(string, **kwargs) # Python 2 ...
|
||||
|
||||
def _search(self, string, all_scopes=False):
|
||||
return self._search_func(string, all_scopes=all_scopes)
|
||||
|
||||
@to_list
|
||||
def _search(self, string, complete=False, all_scopes=False,
|
||||
fuzzy=False):
|
||||
def _search_func(self, string, all_scopes=False, complete=False, fuzzy=False):
|
||||
names = self._names(all_scopes=all_scopes)
|
||||
wanted_type, wanted_names = helpers.split_search_string(string)
|
||||
return search_in_module(
|
||||
@@ -366,6 +364,9 @@ class Script(object):
|
||||
fuzzy=fuzzy,
|
||||
)
|
||||
|
||||
def complete_search(self, string, **kwargs):
|
||||
return self._search_func(string, complete=True, **kwargs)
|
||||
|
||||
@validate_line_column
|
||||
def help(self, line=None, column=None):
|
||||
"""
|
||||
|
||||
@@ -604,6 +604,14 @@ def search_in_module(inference_state, module_context, names, wanted_names,
|
||||
if convert:
|
||||
names = convert_names(names)
|
||||
for n2 in names:
|
||||
def_ = classes.Definition(inference_state, n2)
|
||||
if complete:
|
||||
def_ = classes.Completion(
|
||||
inference_state, n2,
|
||||
stack=None,
|
||||
like_name_length=len(last_name),
|
||||
is_fuzzy=fuzzy,
|
||||
)
|
||||
else:
|
||||
def_ = classes.Definition(inference_state, n2)
|
||||
if not wanted_type or wanted_type == def_.type:
|
||||
yield def_
|
||||
|
||||
@@ -69,6 +69,24 @@ def test_simple_search(Script, string, descriptions, kwargs, skip_pre_python36):
|
||||
if sys.version_info < (3, 6):
|
||||
pytest.skip()
|
||||
|
||||
defs = Script(path=__file__).search(string, **kwargs)
|
||||
if kwargs.pop('complete', False) is True:
|
||||
defs = Script(path=__file__).complete_search(string, **kwargs)
|
||||
else:
|
||||
defs = Script(path=__file__).search(string, **kwargs)
|
||||
this_mod = 'test.test_api.test_search.'
|
||||
assert [d.type + ' ' + d.full_name.replace(this_mod, '') for d in defs] == descriptions
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'string, completions, fuzzy, all_scopes', [
|
||||
('SomeCl', ['ass'], False, False),
|
||||
('SomeCl', [None], True, False),
|
||||
('twic', [], False, False),
|
||||
('some_f', [], False, False),
|
||||
('twic', ['e', 'e'], False, True),
|
||||
('some_f', ['unction'], False, True),
|
||||
]
|
||||
)
|
||||
def test_complete_search(Script, string, completions, fuzzy, all_scopes):
|
||||
defs = Script(path=__file__).complete_search(string, fuzzy=fuzzy, all_scopes=all_scopes)
|
||||
assert [d.complete for d in defs] == completions
|
||||
|
||||
Reference in New Issue
Block a user