mirror of
https://github.com/davidhalter/jedi-vim.git
synced 2025-12-07 03:04:30 +08:00
Truncate long command line call signatures
This commit is contained in:
committed by
Daniel Hahler
parent
9633044332
commit
7abc3ad8d4
81
jedi_vim.py
81
jedi_vim.py
@@ -406,33 +406,65 @@ def cmdline_call_signatures(signatures):
|
|||||||
def get_params(s):
|
def get_params(s):
|
||||||
return [p.description.replace('\n', '') for p in s.params]
|
return [p.description.replace('\n', '') for p in s.params]
|
||||||
|
|
||||||
|
def escape(string):
|
||||||
|
return string.replace('"', '\\"').replace(r'\n', r'\\n')
|
||||||
|
|
||||||
|
def join():
|
||||||
|
return ', '.join(filter(None, (left, center, right)))
|
||||||
|
|
||||||
|
def too_long():
|
||||||
|
return len(join()) > max_msg_len
|
||||||
|
|
||||||
if len(signatures) > 1:
|
if len(signatures) > 1:
|
||||||
params = zip_longest(*map(get_params, signatures), fillvalue='_')
|
params = zip_longest(*map(get_params, signatures), fillvalue='_')
|
||||||
params = ['(' + ', '.join(p) + ')' for p in params]
|
params = ['(' + ', '.join(p) + ')' for p in params]
|
||||||
else:
|
else:
|
||||||
params = get_params(signatures[0])
|
params = get_params(signatures[0])
|
||||||
text = ', '.join(params).replace('"', '\\"').replace(r'\n', r'\\n')
|
|
||||||
|
index = next(iter(s.index for s in signatures if s.index is not None), None)
|
||||||
|
|
||||||
# Allow 12 characters for showcmd plus 18 for ruler - setting
|
# Allow 12 characters for showcmd plus 18 for ruler - setting
|
||||||
# noruler/noshowcmd here causes incorrect undo history
|
# noruler/noshowcmd here causes incorrect undo history
|
||||||
max_msg_len = int(vim_eval('&columns')) - (
|
max_msg_len = int(vim_eval('&columns')) - 12
|
||||||
30 if int(vim_eval('&ruler')) else 12)
|
if int(vim_eval('&ruler')):
|
||||||
max_num_spaces = (max_msg_len - len(signatures[0].call_name)
|
max_msg_len -= 18
|
||||||
- len(text) - 2) # 2 accounts for parentheses
|
max_msg_len -= len(signatures[0].call_name) + 2 # call name + parentheses
|
||||||
if max_num_spaces < 0:
|
|
||||||
return # No room for the message
|
|
||||||
_, column = signatures[0].bracket_start
|
|
||||||
num_spaces = min(int(vim_eval('g:jedi#first_col +'
|
|
||||||
'wincol() - col(".")')) +
|
|
||||||
column - len(signatures[0].call_name),
|
|
||||||
max_num_spaces)
|
|
||||||
spaces = ' ' * num_spaces
|
|
||||||
|
|
||||||
try:
|
if max_msg_len < 0:
|
||||||
index = [s.index for s in signatures if isinstance(s.index, int)][0]
|
return
|
||||||
escaped_param = params[index].replace(r'\n', r'\\n')
|
elif index is None:
|
||||||
left = text.index(escaped_param)
|
pass
|
||||||
right = left + len(escaped_param)
|
elif max_msg_len < len('...'):
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
left = escape(', '.join(params[:index]))
|
||||||
|
center = escape(params[index])
|
||||||
|
right = escape(', '.join(params[index + 1:]))
|
||||||
|
while too_long():
|
||||||
|
if left and left != '...':
|
||||||
|
left = '...'
|
||||||
|
continue
|
||||||
|
if right and right != '...':
|
||||||
|
right = '...'
|
||||||
|
continue
|
||||||
|
if (left or right) and center != '...':
|
||||||
|
left = right = None
|
||||||
|
center = '...'
|
||||||
|
continue
|
||||||
|
if too_long():
|
||||||
|
# Should never reach here
|
||||||
|
return
|
||||||
|
|
||||||
|
max_num_spaces = max_msg_len
|
||||||
|
if index is not None:
|
||||||
|
max_num_spaces -= len(join())
|
||||||
|
_, column = signatures[0].bracket_start
|
||||||
|
spaces = min(int(vim_eval('g:jedi#first_col +'
|
||||||
|
'wincol() - col(".")')) +
|
||||||
|
column - len(signatures[0].call_name),
|
||||||
|
max_num_spaces) * ' '
|
||||||
|
|
||||||
|
if index is not None:
|
||||||
vim_command(' echon "%s" | '
|
vim_command(' echon "%s" | '
|
||||||
'echohl Function | echon "%s" | '
|
'echohl Function | echon "%s" | '
|
||||||
'echohl None | echon "(" | '
|
'echohl None | echon "(" | '
|
||||||
@@ -440,15 +472,14 @@ def cmdline_call_signatures(signatures):
|
|||||||
'echohl jediFat | echon "%s" | '
|
'echohl jediFat | echon "%s" | '
|
||||||
'echohl jediFunction | echon "%s" | '
|
'echohl jediFunction | echon "%s" | '
|
||||||
'echohl None | echon ")"'
|
'echohl None | echon ")"'
|
||||||
% (spaces, signatures[0].call_name, text[:left],
|
% (spaces, signatures[0].call_name,
|
||||||
text[left:right], text[right:]))
|
left + ', ' if left else '',
|
||||||
except (TypeError, IndexError):
|
center, ', ' + right if right else ''))
|
||||||
|
else:
|
||||||
vim_command(' echon "%s" | '
|
vim_command(' echon "%s" | '
|
||||||
'echohl Function | echon "%s" | '
|
'echohl Function | echon "%s" | '
|
||||||
'echohl None | echon "(" | '
|
'echohl None | echon "()"'
|
||||||
'echohl jediFunction | echon "%s" | '
|
% (spaces, signatures[0].call_name))
|
||||||
'echohl None | echon ")"'
|
|
||||||
% (spaces, signatures[0].call_name, text))
|
|
||||||
|
|
||||||
|
|
||||||
@_check_jedi_availability(show_error=True)
|
@_check_jedi_availability(show_error=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user