From 0361d6c63399f5b990dde8ba30e8196be2880bb5 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 4 Jul 2018 17:55:25 +0200 Subject: [PATCH] s:init_python: handle g:jedi#force_py_version again (#834) It was removed previously, since it now refers to the environment being used. This brings it back for now. There could be a separate var for it later, and/or it needs changes later (or rather the environment needs a new variable name, since it should refer to the executable really) - but this is good for now I think. Fixes https://github.com/davidhalter/jedi-vim/issues/833 --- autoload/jedi.vim | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/autoload/jedi.vim b/autoload/jedi.vim index d93c248..699243c 100644 --- a/autoload/jedi.vim +++ b/autoload/jedi.vim @@ -57,14 +57,35 @@ endfor " ------------------------------------------------------------------------ let s:script_path = fnameescape(expand(':p:h:h')) +" Initialize Python (PythonJedi command). function! s:init_python() abort - if has('python3') - call jedi#setup_python_imports(3) - elseif has('python') - call jedi#setup_python_imports(2) + " Use g:jedi#force_py_version for loading Jedi, or fall back to using + " `has()` - preferring Python 3. + let loader_version = get(g:, 'jedi#loader_py_version', g:jedi#force_py_version) + if loader_version ==# 'auto' + if has('python3') + let loader_version = 3 + elseif has('python2') + let loader_version = 2 + else + throw 'jedi-vim requires Vim with support for Python 2 or 3.' + endif else - throw 'jedi-vim requires Vim with support for Python 2 or 3.' + if loader_version =~# '^3' + let loader_version = 3 + elseif loader_version =~# '^2' + let loader_version = 2 + else + if !exists('g:jedi#squelch_py_warning') + echohl WarningMsg + echom printf("jedi-vim: could not determine Python loader version from 'g:jedi#loader_py_version/g:jedi#force_py_version' (%s), using 3.", + \ loader_version) + echohl None + endif + let loader_version = 3 + endif endif + call jedi#setup_python_imports(loader_version) return 1 endfunction