mirror of
https://github.com/davidhalter/jedi-vim.git
synced 2025-12-09 03:54:52 +08:00
Trying to improve jedi-vim, when Jedi is not found. Fixes #263.
This commit is contained in:
@@ -48,7 +48,7 @@ endfun
|
|||||||
" show_documentation
|
" show_documentation
|
||||||
" ------------------------------------------------------------------------
|
" ------------------------------------------------------------------------
|
||||||
function! jedi#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__")
|
let bn = bufnr("__doc__")
|
||||||
if bn > 0
|
if bn > 0
|
||||||
@@ -150,10 +150,6 @@ function! jedi#do_popup_on_dot_in_highlight()
|
|||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
|
||||||
function! jedi#popup_on_dot_string()
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
|
|
||||||
function! jedi#configure_call_signatures()
|
function! jedi#configure_call_signatures()
|
||||||
if g:jedi#show_call_signatures == 2 " Command line 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
|
" Need to track changes to avoid multiple undo points for a single edit
|
||||||
|
|||||||
@@ -18,8 +18,5 @@ import traceback
|
|||||||
|
|
||||||
# update the sys path to include the jedi_vim script
|
# update the sys path to include the jedi_vim script
|
||||||
sys.path.insert(0, vim.eval('expand(s:script_path)'))
|
sys.path.insert(0, vim.eval('expand(s:script_path)'))
|
||||||
try:
|
import jedi_vim
|
||||||
import jedi_vim
|
|
||||||
except ImportError:
|
|
||||||
vim.command('echoerr "Please install Jedi if you want to use jedi_vim."')
|
|
||||||
sys.path.pop(1)
|
sys.path.pop(1)
|
||||||
|
|||||||
56
jedi_vim.py
56
jedi_vim.py
@@ -13,8 +13,29 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
from itertools import izip_longest as zip_longest # Python 2
|
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
|
import vim
|
||||||
import jedi
|
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
|
is_py3 = sys.version_info[0] >= 3
|
||||||
if is_py3:
|
if is_py3:
|
||||||
@@ -31,6 +52,19 @@ def catch_and_print_exceptions(func):
|
|||||||
return wrapper
|
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):
|
class VimError(Exception):
|
||||||
def __init__(self, message, throwpoint, executing):
|
def __init__(self, message, throwpoint, executing):
|
||||||
super(type(self), self).__init__(message)
|
super(type(self), self).__init__(message)
|
||||||
@@ -61,10 +95,6 @@ def vim_command(string):
|
|||||||
_catch_exception(string, 0)
|
_catch_exception(string, 0)
|
||||||
|
|
||||||
|
|
||||||
def echo_highlight(msg):
|
|
||||||
vim_command('echohl WarningMsg | echom "%s" | echohl None' % msg)
|
|
||||||
|
|
||||||
|
|
||||||
class PythonToVimStr(unicode):
|
class PythonToVimStr(unicode):
|
||||||
""" Vim has a different string implementation of single quotes """
|
""" Vim has a different string implementation of single quotes """
|
||||||
__slots__ = []
|
__slots__ = []
|
||||||
@@ -101,6 +131,7 @@ def get_script(source=None, column=None):
|
|||||||
return jedi.Script(source, row, column, buf_path, encoding)
|
return jedi.Script(source, row, column, buf_path, encoding)
|
||||||
|
|
||||||
|
|
||||||
|
@_check_jedi_availability(show_error=False)
|
||||||
@catch_and_print_exceptions
|
@catch_and_print_exceptions
|
||||||
def completions():
|
def completions():
|
||||||
row, column = vim.current.window.cursor
|
row, column = vim.current.window.cursor
|
||||||
@@ -156,6 +187,7 @@ def completions():
|
|||||||
vim.command('return ' + strout)
|
vim.command('return ' + strout)
|
||||||
|
|
||||||
|
|
||||||
|
@_check_jedi_availability(show_error=True)
|
||||||
@catch_and_print_exceptions
|
@catch_and_print_exceptions
|
||||||
def goto(is_definition=False, is_related_name=False, no_output=False):
|
def goto(is_definition=False, is_related_name=False, no_output=False):
|
||||||
definitions = []
|
definitions = []
|
||||||
@@ -208,6 +240,7 @@ def goto(is_definition=False, is_related_name=False, no_output=False):
|
|||||||
return definitions
|
return definitions
|
||||||
|
|
||||||
|
|
||||||
|
@_check_jedi_availability(show_error=True)
|
||||||
@catch_and_print_exceptions
|
@catch_and_print_exceptions
|
||||||
def show_documentation():
|
def show_documentation():
|
||||||
script = get_script()
|
script = get_script()
|
||||||
@@ -230,6 +263,7 @@ def show_documentation():
|
|||||||
text = ('\n' + '-' * 79 + '\n').join(docs)
|
text = ('\n' + '-' * 79 + '\n').join(docs)
|
||||||
vim.command('let l:doc = %s' % repr(PythonToVimStr(text)))
|
vim.command('let l:doc = %s' % repr(PythonToVimStr(text)))
|
||||||
vim.command('let l:doc_lines = %s' % len(text.split('\n')))
|
vim.command('let l:doc_lines = %s' % len(text.split('\n')))
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
@catch_and_print_exceptions
|
@catch_and_print_exceptions
|
||||||
@@ -257,6 +291,7 @@ def clear_call_signatures():
|
|||||||
vim.current.window.cursor = cursor
|
vim.current.window.cursor = cursor
|
||||||
|
|
||||||
|
|
||||||
|
@_check_jedi_availability(show_error=False)
|
||||||
@catch_and_print_exceptions
|
@catch_and_print_exceptions
|
||||||
def show_call_signatures(signatures=()):
|
def show_call_signatures(signatures=()):
|
||||||
if vim_eval("has('conceal') && g:jedi#show_call_signatures") == '0':
|
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))
|
% (spaces, signatures[0].call_name, text))
|
||||||
|
|
||||||
|
|
||||||
|
@_check_jedi_availability(show_error=True)
|
||||||
@catch_and_print_exceptions
|
@catch_and_print_exceptions
|
||||||
def rename():
|
def rename():
|
||||||
if not int(vim.eval('a:0')):
|
if not int(vim.eval('a:0')):
|
||||||
@@ -428,6 +464,7 @@ def rename():
|
|||||||
echo_highlight('Jedi did %s renames!' % len(temp_rename))
|
echo_highlight('Jedi did %s renames!' % len(temp_rename))
|
||||||
|
|
||||||
|
|
||||||
|
@_check_jedi_availability(show_error=True)
|
||||||
@catch_and_print_exceptions
|
@catch_and_print_exceptions
|
||||||
def py_import():
|
def py_import():
|
||||||
# args are the same as for the :edit command
|
# 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):
|
def print_to_stdout(level, str_out):
|
||||||
print(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.')
|
|
||||||
|
|||||||
Reference in New Issue
Block a user