mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-10 07:41:51 +08:00
Add Project.complete_search instead of the complete param
This commit is contained in:
@@ -4,7 +4,7 @@ import json
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
from jedi._compatibility import FileNotFoundError, PermissionError, \
|
from jedi._compatibility import FileNotFoundError, PermissionError, \
|
||||||
IsADirectoryError, scandir
|
IsADirectoryError
|
||||||
from jedi import debug
|
from jedi import debug
|
||||||
from jedi.api.environment import get_cached_default_environment, create_environment
|
from jedi.api.environment import get_cached_default_environment, create_environment
|
||||||
from jedi.api.exceptions import WrongVersion
|
from jedi.api.exceptions import WrongVersion
|
||||||
@@ -191,11 +191,23 @@ class Project(object):
|
|||||||
self._environment = get_cached_default_environment()
|
self._environment = get_cached_default_environment()
|
||||||
return self._environment
|
return self._environment
|
||||||
|
|
||||||
@_try_to_skip_duplicates
|
def search(self, string, **kwargs):
|
||||||
def search(self, string, complete=False, all_scopes=False):
|
|
||||||
"""
|
"""
|
||||||
Returns a generator of names
|
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.
|
# Using a Script is they easiest way to get an empty module context.
|
||||||
from jedi import Script
|
from jedi import Script
|
||||||
s = Script('', project=self)
|
s = Script('', project=self)
|
||||||
|
|||||||
@@ -131,5 +131,22 @@ def test_load_save_project(tmpdir):
|
|||||||
def test_search(string, full_names, kwargs, skip_pre_python36):
|
def test_search(string, full_names, kwargs, skip_pre_python36):
|
||||||
some_search_test_var = 1.0
|
some_search_test_var = 1.0
|
||||||
project = Project(test_dir)
|
project = Project(test_dir)
|
||||||
|
if kwargs.pop('complete', False) is True:
|
||||||
|
defs = project.complete_search(string, **kwargs)
|
||||||
|
else:
|
||||||
defs = project.search(string, **kwargs)
|
defs = project.search(string, **kwargs)
|
||||||
assert [('stub:' if d.is_stub() else '') + d.full_name for d in defs] == full_names
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user