diff --git a/jedi/api/project.py b/jedi/api/project.py index ae837b90..cbfb6bc8 100644 --- a/jedi/api/project.py +++ b/jedi/api/project.py @@ -4,7 +4,7 @@ import json import sys from jedi._compatibility import FileNotFoundError, PermissionError, \ - IsADirectoryError, scandir + IsADirectoryError from jedi import debug from jedi.api.environment import get_cached_default_environment, create_environment from jedi.api.exceptions import WrongVersion @@ -191,11 +191,23 @@ class Project(object): self._environment = get_cached_default_environment() return self._environment - @_try_to_skip_duplicates - def search(self, string, complete=False, all_scopes=False): + def search(self, string, **kwargs): """ Returns a generator of names """ + return self._search(string, **kwargs) + + def complete_search(self, string, **kwargs): + """ + + """ + return self._search_func(string, complete=True, **kwargs) + + def _search(self, string, all_scopes=False): # Python 2.. + return self._search_func(string, all_scopes=all_scopes) + + @_try_to_skip_duplicates + def _search_func(self, string, complete=False, all_scopes=False): # Using a Script is they easiest way to get an empty module context. from jedi import Script s = Script('', project=self) diff --git a/test/test_api/test_project.py b/test/test_api/test_project.py index 9cbc4561..72887853 100644 --- a/test/test_api/test_project.py +++ b/test/test_api/test_project.py @@ -131,5 +131,22 @@ def test_load_save_project(tmpdir): def test_search(string, full_names, kwargs, skip_pre_python36): some_search_test_var = 1.0 project = Project(test_dir) - defs = project.search(string, **kwargs) + if kwargs.pop('complete', False) is True: + defs = project.complete_search(string, **kwargs) + else: + defs = project.search(string, **kwargs) assert [('stub:' if d.is_stub() else '') + d.full_name for d in defs] == full_names + + +@pytest.mark.parametrize( + 'string, completions, all_scopes', [ + ('SomeCl', ['ass'], False), + ('twic', [], False), + ('twic', ['e', 'e'], True), + ('test_load_save_p', ['roject'], False), + ] +) +def test_complete_search(Script, string, completions, all_scopes): + project = Project(test_dir) + defs = project.complete_search(string, all_scopes=all_scopes) + assert [d.complete for d in defs] == completions