mirror of
https://github.com/davidhalter/jedi-vim.git
synced 2025-12-07 11:14:32 +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
2
.gitmodules
vendored
2
.gitmodules
vendored
@@ -1,3 +1,3 @@
|
|||||||
[submodule "jedi"]
|
[submodule "jedi"]
|
||||||
path = jedi
|
path = pythonx/jedi
|
||||||
url = https://github.com/davidhalter/jedi.git
|
url = https://github.com/davidhalter/jedi.git
|
||||||
|
|||||||
@@ -152,29 +152,20 @@ function! jedi#setup_py_version(py_version) abort
|
|||||||
|
|
||||||
execute 'command! -nargs=1 PythonJedi '.cmd_exec.' <args>'
|
execute 'command! -nargs=1 PythonJedi '.cmd_exec.' <args>'
|
||||||
|
|
||||||
let s:init_outcome = 0
|
let init_lines = [
|
||||||
PythonJedi << EOF
|
\ 'import vim',
|
||||||
try:
|
\ 'vim.command(''let s:init_outcome = 0'')',
|
||||||
import vim
|
\ 'try:',
|
||||||
import os, sys
|
\ ' import jedi_vim',
|
||||||
jedi_path = os.path.join(vim.eval('expand(s:script_path)'), 'jedi')
|
\ 'except Exception as exc:',
|
||||||
sys.path.insert(0, jedi_path)
|
\ ' vim.command(''let s:init_outcome = "could not import jedi_vim: {0}: {1}"''.format(exc.__class__.__name__, exc))',
|
||||||
|
\ 'else:',
|
||||||
jedi_vim_path = vim.eval('expand(s:script_path)')
|
\ ' vim.command(''let s:init_outcome = 1'')']
|
||||||
if jedi_vim_path not in sys.path: # Might happen when reloading.
|
try
|
||||||
sys.path.insert(0, jedi_vim_path)
|
exe 'PythonJedi exec('''.escape(join(init_lines, '\n'), "'").''')'
|
||||||
except Exception as excinfo:
|
catch
|
||||||
vim.command('let s:init_outcome = "error when adding to sys.path: {0}: {1}"'.format(excinfo.__class__.__name__, excinfo))
|
throw printf('jedi#setup_py_version: failed to run Python for initialization: %s.', v:exception)
|
||||||
else:
|
endtry
|
||||||
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
|
|
||||||
if !exists('s:init_outcome')
|
if !exists('s:init_outcome')
|
||||||
throw 'jedi#setup_py_version: failed to run Python for initialization.'
|
throw 'jedi#setup_py_version: failed to run Python for initialization.'
|
||||||
elseif s:init_outcome isnot 1
|
elseif s:init_outcome isnot 1
|
||||||
|
|||||||
@@ -93,6 +93,9 @@ def echo_highlight(msg):
|
|||||||
str(msg).replace('"', '\\"')))
|
str(msg).replace('"', '\\"')))
|
||||||
|
|
||||||
|
|
||||||
|
jedi_path = os.path.join(os.path.dirname(__file__), 'jedi')
|
||||||
|
sys.path.insert(0, jedi_path)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import jedi
|
import jedi
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
@@ -115,6 +118,8 @@ else:
|
|||||||
version = utils.version_info()
|
version = utils.version_info()
|
||||||
if version < (0, 7):
|
if version < (0, 7):
|
||||||
echo_highlight('Please update your Jedi version, it is too old.')
|
echo_highlight('Please update your Jedi version, it is too old.')
|
||||||
|
finally:
|
||||||
|
sys.path.remove(jedi_path)
|
||||||
|
|
||||||
|
|
||||||
def catch_and_print_exceptions(func):
|
def catch_and_print_exceptions(func):
|
||||||
Reference in New Issue
Block a user