mirror of
https://github.com/davidhalter/jedi-vim.git
synced 2025-12-06 10:54:22 +08:00
Use Vim's pythonx mechanism
Move jedi_vim.py and the jedi submodule into pythonx, which gets added to Vim's internal sys.path. While jedi cannot be imported directly from there, it still makes sense for consistency.
This commit is contained in:
committed by
Dave Halter
parent
cfadac7f22
commit
163a0b5db1
@@ -152,29 +152,20 @@ function! jedi#setup_py_version(py_version) abort
|
||||
|
||||
execute 'command! -nargs=1 PythonJedi '.cmd_exec.' <args>'
|
||||
|
||||
let s:init_outcome = 0
|
||||
PythonJedi << EOF
|
||||
try:
|
||||
import vim
|
||||
import os, sys
|
||||
jedi_path = os.path.join(vim.eval('expand(s:script_path)'), 'jedi')
|
||||
sys.path.insert(0, jedi_path)
|
||||
|
||||
jedi_vim_path = vim.eval('expand(s:script_path)')
|
||||
if jedi_vim_path not in sys.path: # Might happen when reloading.
|
||||
sys.path.insert(0, jedi_vim_path)
|
||||
except Exception as excinfo:
|
||||
vim.command('let s:init_outcome = "error when adding to sys.path: {0}: {1}"'.format(excinfo.__class__.__name__, excinfo))
|
||||
else:
|
||||
try:
|
||||
import jedi_vim
|
||||
except Exception as excinfo:
|
||||
vim.command('let s:init_outcome = "error when importing jedi_vim: {0}: {1}"'.format(excinfo.__class__.__name__, excinfo))
|
||||
else:
|
||||
vim.command('let s:init_outcome = 1')
|
||||
finally:
|
||||
sys.path.remove(jedi_path)
|
||||
EOF
|
||||
let init_lines = [
|
||||
\ 'import vim',
|
||||
\ 'vim.command(''let s:init_outcome = 0'')',
|
||||
\ 'try:',
|
||||
\ ' import jedi_vim',
|
||||
\ 'except Exception as exc:',
|
||||
\ ' vim.command(''let s:init_outcome = "could not import jedi_vim: {0}: {1}"''.format(exc.__class__.__name__, exc))',
|
||||
\ 'else:',
|
||||
\ ' vim.command(''let s:init_outcome = 1'')']
|
||||
try
|
||||
exe 'PythonJedi exec('''.escape(join(init_lines, '\n'), "'").''')'
|
||||
catch
|
||||
throw printf('jedi#setup_py_version: failed to run Python for initialization: %s.', v:exception)
|
||||
endtry
|
||||
if !exists('s:init_outcome')
|
||||
throw 'jedi#setup_py_version: failed to run Python for initialization.'
|
||||
elseif s:init_outcome isnot 1
|
||||
|
||||
Reference in New Issue
Block a user