Implement :JediChooseEnvironment

This commit is contained in:
Dave Halter
2020-07-31 15:06:09 +02:00
parent 104d817f0c
commit e23687462b
3 changed files with 26 additions and 5 deletions

View File

@@ -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

View File

@@ -53,6 +53,9 @@ endif
" Pyimport command
command! -nargs=1 -complete=custom,jedi#py_import_completions Pyimport :call jedi#py_import(<q-args>)
command! -nargs=? -complete=file JediChooseEnvironment :call jedi#choose_environment(<q-args>)
function! s:jedi_debug_info()
" Ensure the autoload file has been loaded (and ignore any errors, which
" will be displayed with the debug info).

View File

@@ -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 <buffer> <ESC> :bd<CR>')
vim_command('noremap <buffer> <CR> :PythonJedi jedi_vim.choose_environment_hit_enter()<CR>')
def choose_environment_hit_enter():
vim.vars['jedi#environment_path'] = vim.current.line
vim_command('bd')
@catch_and_print_exceptions