diff --git a/autoload/jedi.vim b/autoload/jedi.vim index 9275d59..2786e2e 100644 --- a/autoload/jedi.vim +++ b/autoload/jedi.vim @@ -424,6 +424,10 @@ function! jedi#py_import(args) abort PythonJedi jedi_vim.py_import() endfun +function! jedi#choose_environment(args) abort + PythonJedi jedi_vim.choose_environment() +endfun + function! jedi#py_import_completions(argl, cmdl, pos) abort PythonJedi jedi_vim.py_import_completions() endfun diff --git a/plugin/jedi.vim b/plugin/jedi.vim index f8fe4b2..245548a 100644 --- a/plugin/jedi.vim +++ b/plugin/jedi.vim @@ -53,6 +53,9 @@ endif " Pyimport command command! -nargs=1 -complete=custom,jedi#py_import_completions Pyimport :call jedi#py_import() +command! -nargs=? -complete=file JediChooseEnvironment :call jedi#choose_environment() + + function! s:jedi_debug_info() " Ensure the autoload file has been loaded (and ignore any errors, which " will be displayed with the debug info). diff --git a/pythonx/jedi_vim.py b/pythonx/jedi_vim.py index 2d39f1d..1fd0fa6 100644 --- a/pythonx/jedi_vim.py +++ b/pythonx/jedi_vim.py @@ -240,11 +240,25 @@ def get_project(): return project -def get_known_environments(): - """Get known Jedi environments.""" - envs = list(jedi.api.environment.find_virtualenvs()) - envs.extend(jedi.api.environment.find_system_environments()) - return envs +def choose_environment(): + args = shsplit(vim.eval('a:args')) + + envs = list(jedi.find_system_environments()) + envs.extend(jedi.find_virtualenvs(paths=args or None)) + + env_paths = [env.executable for env in envs] + + vim_command('belowright new') + vim.current.buffer[:] = env_paths + vim.current.buffer.name = "Hit Enter to Choose an Environment" + vim_command('setlocal buftype=nofile bufhidden=hide noswapfile readonly nomodifiable') + vim_command('noremap :bd') + vim_command('noremap :PythonJedi jedi_vim.choose_environment_hit_enter()') + + +def choose_environment_hit_enter(): + vim.vars['jedi#environment_path'] = vim.current.line + vim_command('bd') @catch_and_print_exceptions