mirror of
https://github.com/davidhalter/jedi-vim.git
synced 2025-12-07 03:04:30 +08:00
Implement :JediChooseEnvironment
This commit is contained in:
@@ -424,6 +424,10 @@ function! jedi#py_import(args) abort
|
|||||||
PythonJedi jedi_vim.py_import()
|
PythonJedi jedi_vim.py_import()
|
||||||
endfun
|
endfun
|
||||||
|
|
||||||
|
function! jedi#choose_environment(args) abort
|
||||||
|
PythonJedi jedi_vim.choose_environment()
|
||||||
|
endfun
|
||||||
|
|
||||||
function! jedi#py_import_completions(argl, cmdl, pos) abort
|
function! jedi#py_import_completions(argl, cmdl, pos) abort
|
||||||
PythonJedi jedi_vim.py_import_completions()
|
PythonJedi jedi_vim.py_import_completions()
|
||||||
endfun
|
endfun
|
||||||
|
|||||||
@@ -53,6 +53,9 @@ endif
|
|||||||
" Pyimport command
|
" Pyimport command
|
||||||
command! -nargs=1 -complete=custom,jedi#py_import_completions Pyimport :call jedi#py_import(<q-args>)
|
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()
|
function! s:jedi_debug_info()
|
||||||
" Ensure the autoload file has been loaded (and ignore any errors, which
|
" Ensure the autoload file has been loaded (and ignore any errors, which
|
||||||
" will be displayed with the debug info).
|
" will be displayed with the debug info).
|
||||||
|
|||||||
@@ -240,11 +240,25 @@ def get_project():
|
|||||||
return project
|
return project
|
||||||
|
|
||||||
|
|
||||||
def get_known_environments():
|
def choose_environment():
|
||||||
"""Get known Jedi environments."""
|
args = shsplit(vim.eval('a:args'))
|
||||||
envs = list(jedi.api.environment.find_virtualenvs())
|
|
||||||
envs.extend(jedi.api.environment.find_system_environments())
|
envs = list(jedi.find_system_environments())
|
||||||
return envs
|
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
|
@catch_and_print_exceptions
|
||||||
|
|||||||
Reference in New Issue
Block a user