Trying to improve jedi-vim, when Jedi is not found. Fixes #263.

This commit is contained in:
Dave Halter
2015-03-30 19:11:05 +02:00
parent cc9837dc23
commit e87e7db0e9
3 changed files with 44 additions and 23 deletions

View File

@@ -48,7 +48,7 @@ endfun
" show_documentation
" ------------------------------------------------------------------------
function! jedi#show_documentation()
Python jedi_vim.show_documentation()
Python if jedi_vim.show_documentation() is None: vim.command('return')
let bn = bufnr("__doc__")
if bn > 0
@@ -150,10 +150,6 @@ function! jedi#do_popup_on_dot_in_highlight()
endfunc
function! jedi#popup_on_dot_string()
endfunction
function! jedi#configure_call_signatures()
if g:jedi#show_call_signatures == 2 " Command line call signatures
" Need to track changes to avoid multiple undo points for a single edit

View File

@@ -18,8 +18,5 @@ import traceback
# update the sys path to include the jedi_vim script
sys.path.insert(0, vim.eval('expand(s:script_path)'))
try:
import jedi_vim
except ImportError:
vim.command('echoerr "Please install Jedi if you want to use jedi_vim."')
sys.path.pop(1)

View File

@@ -13,8 +13,29 @@ try:
except ImportError:
from itertools import izip_longest as zip_longest # Python 2
def no_jedi_warning():
vim.command('echoerr "Please install Jedi if you want to use jedi_vim."')
def echo_highlight(msg):
vim_command('echohl WarningMsg | echom "%s" | echohl None' % msg)
import vim
try:
import jedi
except ImportError:
no_jedi_warning()
jedi = None
else:
version = jedi.__version__
if isinstance(version, str):
# the normal use case, now.
from jedi import utils
version = utils.version_info()
if version < (0, 7):
echo_highlight('Please update your Jedi version, it is to old.')
is_py3 = sys.version_info[0] >= 3
if is_py3:
@@ -31,6 +52,19 @@ def catch_and_print_exceptions(func):
return wrapper
def _check_jedi_availability(show_error=False):
def func_receiver(func):
def wrapper(*args, **kwargs):
if jedi is None:
if show_error:
no_jedi_warning()
return
else:
return func(*args, **kwargs)
return wrapper
return func_receiver
class VimError(Exception):
def __init__(self, message, throwpoint, executing):
super(type(self), self).__init__(message)
@@ -61,10 +95,6 @@ def vim_command(string):
_catch_exception(string, 0)
def echo_highlight(msg):
vim_command('echohl WarningMsg | echom "%s" | echohl None' % msg)
class PythonToVimStr(unicode):
""" Vim has a different string implementation of single quotes """
__slots__ = []
@@ -101,6 +131,7 @@ def get_script(source=None, column=None):
return jedi.Script(source, row, column, buf_path, encoding)
@_check_jedi_availability(show_error=False)
@catch_and_print_exceptions
def completions():
row, column = vim.current.window.cursor
@@ -156,6 +187,7 @@ def completions():
vim.command('return ' + strout)
@_check_jedi_availability(show_error=True)
@catch_and_print_exceptions
def goto(is_definition=False, is_related_name=False, no_output=False):
definitions = []
@@ -208,6 +240,7 @@ def goto(is_definition=False, is_related_name=False, no_output=False):
return definitions
@_check_jedi_availability(show_error=True)
@catch_and_print_exceptions
def show_documentation():
script = get_script()
@@ -230,6 +263,7 @@ def show_documentation():
text = ('\n' + '-' * 79 + '\n').join(docs)
vim.command('let l:doc = %s' % repr(PythonToVimStr(text)))
vim.command('let l:doc_lines = %s' % len(text.split('\n')))
return True
@catch_and_print_exceptions
@@ -257,6 +291,7 @@ def clear_call_signatures():
vim.current.window.cursor = cursor
@_check_jedi_availability(show_error=False)
@catch_and_print_exceptions
def show_call_signatures(signatures=()):
if vim_eval("has('conceal') && g:jedi#show_call_signatures") == '0':
@@ -376,6 +411,7 @@ def cmdline_call_signatures(signatures):
% (spaces, signatures[0].call_name, text))
@_check_jedi_availability(show_error=True)
@catch_and_print_exceptions
def rename():
if not int(vim.eval('a:0')):
@@ -428,6 +464,7 @@ def rename():
echo_highlight('Jedi did %s renames!' % len(temp_rename))
@_check_jedi_availability(show_error=True)
@catch_and_print_exceptions
def py_import():
# args are the same as for the :edit command
@@ -538,12 +575,3 @@ def escape_file_path(path):
def print_to_stdout(level, str_out):
print(str_out)
version = jedi.__version__
if isinstance(version, str):
# the normal use case, now.
from jedi import utils
version = utils.version_info()
if version < (0, 7):
echo_highlight('Please update your Jedi version, it is to old.')