From 81e1e9ca3443b4185d92f9eca41a6cd2d89f0459 Mon Sep 17 00:00:00 2001 From: James Cherti <60946298+jamescherti@users.noreply.github.com> Date: Mon, 21 Jun 2021 14:58:57 -0400 Subject: [PATCH 1/2] The buffer-local variable `b:jedi_environment_path` was added to override the global variable `g:jedi#environment_path`. --- doc/jedi-vim.txt | 6 ++++++ pythonx/jedi_vim.py | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/doc/jedi-vim.txt b/doc/jedi-vim.txt index 48dd5d0..dc2d24d 100644 --- a/doc/jedi-vim.txt +++ b/doc/jedi-vim.txt @@ -45,6 +45,7 @@ Contents *jedi-vim-contents* 6.13. smart_auto_mappings |g:jedi#smart_auto_mappings| 6.14. use_tag_stack |g:jedi#use_tag_stack| 6.15. environment_path |g:jedi#environment_path| + |b:jedi_environment_path| 6.16. added_sys_path |g:jedi#added_sys_path| 7. Testing |jedi-vim-testing| 8. Contributing |jedi-vim-contributing| @@ -510,6 +511,7 @@ Default: 1 (enabled by default) ------------------------------------------------------------------------------ 6.15. `g:jedi#environment_path` *g:jedi#environment_path* + *b:jedi_environment_path* To use a specific virtualenv or a specific Python version it is possible to set an interpreter. @@ -517,6 +519,10 @@ set an interpreter. Both setting the directory and setting a project is working. Examples: "/usr/bin/python3.9", "venv", "../venv", "../venv/bin/python" + +The buffer-local variable `b:jedi_environment_path` can be used to override the +global variable `g:jedi#environment_path`. + Default: "auto" ------------------------------------------------------------------------------ diff --git a/pythonx/jedi_vim.py b/pythonx/jedi_vim.py index f0ca158..81ea69e 100644 --- a/pythonx/jedi_vim.py +++ b/pythonx/jedi_vim.py @@ -218,7 +218,9 @@ _current_project_cache = None, None def get_project(): - vim_environment_path = vim_eval("g:jedi#environment_path") + vim_environment_path = vim_eval("b:jedi_environment_path") + if vim_environment_path in ("", None): + vim_environment_path = vim_eval("g:jedi#environment_path") vim_project_path = vim_eval("g:jedi#project_path") vim_added_sys_path = vim_eval("g:jedi#added_sys_path") From 81002ed6e74033c7c8638313b7e2ae74f42cc04c Mon Sep 17 00:00:00 2001 From: James Cherti <60946298+jamescherti@users.noreply.github.com> Date: Tue, 22 Jun 2021 13:42:11 -0400 Subject: [PATCH 2/2] This commit fixes the exception: jedi_vim.VimError: Vim(let):E121: Undefined variable: b:jedi_environment_path; created by 'b:jedi_environment_path' --- pythonx/jedi_vim.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pythonx/jedi_vim.py b/pythonx/jedi_vim.py index 81ea69e..7aef072 100644 --- a/pythonx/jedi_vim.py +++ b/pythonx/jedi_vim.py @@ -218,7 +218,11 @@ _current_project_cache = None, None def get_project(): - vim_environment_path = vim_eval("b:jedi_environment_path") + try: + vim_environment_path = vim_eval("b:jedi_environment_path") + except VimError: + vim_environment_path = "" + if vim_environment_path in ("", None): vim_environment_path = vim_eval("g:jedi#environment_path") vim_project_path = vim_eval("g:jedi#project_path")