mirror of
https://github.com/davidhalter/jedi-vim.git
synced 2025-12-07 03:04:30 +08:00
Use projects instead of environments
This commit is contained in:
@@ -92,11 +92,6 @@ def vim_eval(string):
|
|||||||
return _catch_exception(string, is_eval=True)
|
return _catch_exception(string, is_eval=True)
|
||||||
|
|
||||||
|
|
||||||
def get_project():
|
|
||||||
# TODO remove get_environment() in favor of this.
|
|
||||||
return jedi.get_default_project()
|
|
||||||
|
|
||||||
|
|
||||||
def no_jedi_warning(error=None):
|
def no_jedi_warning(error=None):
|
||||||
vim.command('echohl WarningMsg')
|
vim.command('echohl WarningMsg')
|
||||||
vim.command('echom "Please install Jedi if you want to use jedi-vim."')
|
vim.command('echom "Please install Jedi if you want to use jedi-vim."')
|
||||||
@@ -216,40 +211,37 @@ def _check_jedi_availability(show_error=False):
|
|||||||
return func_receiver
|
return func_receiver
|
||||||
|
|
||||||
|
|
||||||
current_environment = (None, None)
|
_current_project_cache = None, None
|
||||||
|
|
||||||
|
|
||||||
def get_environment(use_cache=True):
|
def _create_project_cache_key(project_path, environment_path):
|
||||||
global current_environment
|
return dict(project_path=project_path, environment_path=environment_path)
|
||||||
|
|
||||||
vim_force_python_version = vim_eval("g:jedi#force_py_version")
|
|
||||||
if use_cache and vim_force_python_version == current_environment[0]:
|
|
||||||
return current_environment[1]
|
|
||||||
|
|
||||||
environment = None
|
def get_project():
|
||||||
if vim_force_python_version == "auto":
|
global _current_project_cache
|
||||||
environment = jedi.api.environment.get_cached_default_environment()
|
|
||||||
|
vim_environment_path = vim_eval("g:jedi#environment_path")
|
||||||
|
vim_project_path = vim_eval("g:jedi#project_path")
|
||||||
|
cache_key = _create_project_cache_key(vim_project_path, vim_environment_path)
|
||||||
|
|
||||||
|
if cache_key == _current_project_cache[0]:
|
||||||
|
return _current_project_cache[1]
|
||||||
|
|
||||||
|
if vim_environment_path in ("auto", "", None):
|
||||||
|
environment_path = None
|
||||||
else:
|
else:
|
||||||
force_python_version = vim_force_python_version
|
environment_path = vim_environment_path
|
||||||
if '0000' in force_python_version or '9999' in force_python_version:
|
|
||||||
# It's probably a float that wasn't shortened.
|
|
||||||
try:
|
|
||||||
force_python_version = "{:.1f}".format(float(force_python_version))
|
|
||||||
except ValueError:
|
|
||||||
pass
|
|
||||||
elif isinstance(force_python_version, float):
|
|
||||||
force_python_version = "{:.1f}".format(force_python_version)
|
|
||||||
|
|
||||||
try:
|
if vim_project_path == ("auto", "", None):
|
||||||
environment = jedi.get_system_environment(force_python_version)
|
project_path = jedi.get_default_project().path
|
||||||
except jedi.InvalidPythonEnvironment as exc:
|
else:
|
||||||
environment = jedi.api.environment.get_cached_default_environment()
|
project_path = vim_project_path
|
||||||
echo_highlight(
|
|
||||||
"force_python_version=%s is not supported: %s - using %s." % (
|
|
||||||
vim_force_python_version, str(exc), str(environment)))
|
|
||||||
|
|
||||||
current_environment = (vim_force_python_version, environment)
|
project = jedi.Project(project_path, environment_path=environment_path)
|
||||||
return environment
|
|
||||||
|
_current_project_cache = cache_key, project
|
||||||
|
return project
|
||||||
|
|
||||||
|
|
||||||
def get_known_environments():
|
def get_known_environments():
|
||||||
@@ -270,7 +262,7 @@ def get_script(source=None):
|
|||||||
source = '\n'.join(vim.current.buffer)
|
source = '\n'.join(vim.current.buffer)
|
||||||
buf_path = vim.current.buffer.name
|
buf_path = vim.current.buffer.name
|
||||||
|
|
||||||
return jedi.Script(source, path=buf_path, environment=get_environment())
|
return jedi.Script(source, path=buf_path, project=get_project())
|
||||||
|
|
||||||
|
|
||||||
def get_pos(column=None):
|
def get_pos(column=None):
|
||||||
@@ -1067,7 +1059,7 @@ def py_import_completions():
|
|||||||
comps = []
|
comps = []
|
||||||
else:
|
else:
|
||||||
names = get_project().complete_search(argl)
|
names = get_project().complete_search(argl)
|
||||||
comps = [argl + n for n in set(c.complete for c in names)]
|
comps = [argl + n for n in sorted(set(c.complete for c in names))]
|
||||||
vim.command("return '%s'" % '\n'.join(comps))
|
vim.command("return '%s'" % '\n'.join(comps))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -58,7 +58,8 @@ def display_debug_info():
|
|||||||
echo(' - version: {0}'.format(jedi_vim.jedi.__version__))
|
echo(' - version: {0}'.format(jedi_vim.jedi.__version__))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
environment = jedi_vim.get_environment(use_cache=False)
|
project = jedi_vim.get_project()
|
||||||
|
environment = project.get_environment()
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
script_evaluator = jedi_vim.jedi.Script('')._evaluator
|
script_evaluator = jedi_vim.jedi.Script('')._evaluator
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user