From 9633044332dd2b467ee590dd5e9c3263ad9072b8 Mon Sep 17 00:00:00 2001 From: Jacob Niehus Date: Wed, 14 Oct 2015 20:34:01 -0700 Subject: [PATCH 1/4] Allow fewer columns in call signatures if 'ruler' is set --- jedi_vim.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/jedi_vim.py b/jedi_vim.py index c92b7f1..d284fc6 100644 --- a/jedi_vim.py +++ b/jedi_vim.py @@ -413,9 +413,10 @@ def cmdline_call_signatures(signatures): params = get_params(signatures[0]) text = ', '.join(params).replace('"', '\\"').replace(r'\n', r'\\n') - # Allow 12 characters for ruler/showcmd - setting noruler/noshowcmd - # here causes incorrect undo history - max_msg_len = int(vim_eval('&columns')) - 12 + # Allow 12 characters for showcmd plus 18 for ruler - setting + # noruler/noshowcmd here causes incorrect undo history + max_msg_len = int(vim_eval('&columns')) - ( + 30 if int(vim_eval('&ruler')) else 12) max_num_spaces = (max_msg_len - len(signatures[0].call_name) - len(text) - 2) # 2 accounts for parentheses if max_num_spaces < 0: From 7abc3ad8d4d73eda65b4c3dbc4b9569cfa750ca1 Mon Sep 17 00:00:00 2001 From: Jacob Niehus Date: Fri, 16 Oct 2015 10:47:19 -0700 Subject: [PATCH 2/4] Truncate long command line call signatures --- jedi_vim.py | 81 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 56 insertions(+), 25 deletions(-) diff --git a/jedi_vim.py b/jedi_vim.py index d284fc6..e9d8be3 100644 --- a/jedi_vim.py +++ b/jedi_vim.py @@ -406,33 +406,65 @@ def cmdline_call_signatures(signatures): def get_params(s): 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: params = zip_longest(*map(get_params, signatures), fillvalue='_') params = ['(' + ', '.join(p) + ')' for p in params] else: 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 # noruler/noshowcmd here causes incorrect undo history - max_msg_len = int(vim_eval('&columns')) - ( - 30 if int(vim_eval('&ruler')) else 12) - max_num_spaces = (max_msg_len - len(signatures[0].call_name) - - len(text) - 2) # 2 accounts for 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 + max_msg_len = int(vim_eval('&columns')) - 12 + if int(vim_eval('&ruler')): + max_msg_len -= 18 + max_msg_len -= len(signatures[0].call_name) + 2 # call name + parentheses - try: - index = [s.index for s in signatures if isinstance(s.index, int)][0] - escaped_param = params[index].replace(r'\n', r'\\n') - left = text.index(escaped_param) - right = left + len(escaped_param) + if max_msg_len < 0: + return + elif index is None: + pass + 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" | ' 'echohl Function | echon "%s" | ' 'echohl None | echon "(" | ' @@ -440,15 +472,14 @@ def cmdline_call_signatures(signatures): 'echohl jediFat | echon "%s" | ' 'echohl jediFunction | echon "%s" | ' 'echohl None | echon ")"' - % (spaces, signatures[0].call_name, text[:left], - text[left:right], text[right:])) - except (TypeError, IndexError): + % (spaces, signatures[0].call_name, + left + ', ' if left else '', + center, ', ' + right if right else '')) + else: vim_command(' echon "%s" | ' 'echohl Function | echon "%s" | ' - 'echohl None | echon "(" | ' - 'echohl jediFunction | echon "%s" | ' - 'echohl None | echon ")"' - % (spaces, signatures[0].call_name, text)) + 'echohl None | echon "()"' + % (spaces, signatures[0].call_name)) @_check_jedi_availability(show_error=True) From 62c423bf298a9a9dbf53ed4acc9055c5cd29deb5 Mon Sep 17 00:00:00 2001 From: Jacob Niehus Date: Fri, 16 Oct 2015 19:16:24 -0700 Subject: [PATCH 3/4] Add test case for truncation of cmdline signatures --- test/signatures.vim | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/test/signatures.vim b/test/signatures.vim index b2c57e7..c69d9f6 100644 --- a/test/signatures.vim +++ b/test/signatures.vim @@ -53,6 +53,39 @@ describe 'signatures' Expect msg == "\n" end + it 'command line truncation' + let g:jedi#show_call_signatures = 2 + call jedi#configure_call_signatures() + + function! Signature() + redir => msg + Python jedi_vim.show_call_signatures() + redir END + return msg + endfunction + + let funcname = repeat('a', &columns - 30) + put = 'def '.funcname.'(arg1, arg2, arg3, a, b, c):' + put = ' pass' + execute "normal o".funcname."( " + Expect Signature() == "\n".funcname."(arg1, ...)" + + normal sarg1, + Expect Signature() == "\n".funcname."(..., arg2, ...)" + + normal sarg2, arg3, + Expect Signature() == "\n".funcname."(..., a, b, c)" + + normal sa, b, + Expect Signature() == "\n".funcname."(..., c)" + + g/^/d + put = 'def '.funcname.'('.repeat('b', 20).', arg2):' + put = ' pass' + execute "normal o".funcname."( " + Expect Signature() == "\n".funcname."(...)" + end + it 'command line no signature' let g:jedi#show_call_signatures = 2 call jedi#configure_call_signatures() From 5c868b9a1f6f808ede1a0b1749e518dded152581 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sun, 18 Oct 2015 15:08:17 +0200 Subject: [PATCH 4/4] Use utf8 ellipsis char instead of 3 dots --- jedi_vim.py | 18 +++++++++++------- test/signatures.vim | 10 +++++----- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/jedi_vim.py b/jedi_vim.py index e9d8be3..8d3a92b 100644 --- a/jedi_vim.py +++ b/jedi_vim.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- """ The Python parts of the Jedi library for VIM. It is mostly about communicating with VIM. @@ -18,7 +19,10 @@ except ImportError: is_py3 = sys.version_info[0] >= 3 if is_py3: + ELLIPSIS = "…" unicode = str +else: + ELLIPSIS = u"…" class PythonToVimStr(unicode): @@ -434,22 +438,22 @@ def cmdline_call_signatures(signatures): return elif index is None: pass - elif max_msg_len < len('...'): + elif max_msg_len < len(ELLIPSIS): 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 = '...' + if left and left != ELLIPSIS: + left = ELLIPSIS continue - if right and right != '...': - right = '...' + if right and right != ELLIPSIS: + right = ELLIPSIS continue - if (left or right) and center != '...': + if (left or right) and center != ELLIPSIS: left = right = None - center = '...' + center = ELLIPSIS continue if too_long(): # Should never reach here diff --git a/test/signatures.vim b/test/signatures.vim index c69d9f6..70f417c 100644 --- a/test/signatures.vim +++ b/test/signatures.vim @@ -68,22 +68,22 @@ describe 'signatures' put = 'def '.funcname.'(arg1, arg2, arg3, a, b, c):' put = ' pass' execute "normal o".funcname."( " - Expect Signature() == "\n".funcname."(arg1, ...)" + Expect Signature() == "\n".funcname."(arg1, …)" normal sarg1, - Expect Signature() == "\n".funcname."(..., arg2, ...)" + Expect Signature() == "\n".funcname."(…, arg2, …)" normal sarg2, arg3, - Expect Signature() == "\n".funcname."(..., a, b, c)" + Expect Signature() == "\n".funcname."(…, a, b, c)" normal sa, b, - Expect Signature() == "\n".funcname."(..., c)" + Expect Signature() == "\n".funcname."(…, c)" g/^/d put = 'def '.funcname.'('.repeat('b', 20).', arg2):' put = ' pass' execute "normal o".funcname."( " - Expect Signature() == "\n".funcname."(...)" + Expect Signature() == "\n".funcname."(…)" end it 'command line no signature'