From e241cf87fdccaa4f5eec48d4e4063920f2dfddea Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Fri, 3 Jul 2015 15:31:09 +0200 Subject: [PATCH] Conditionally skip calls to jedi_vim.show_call_signatures Skip calls to `jedi_vim.show_call_signatures` if the (position of the) current function's argument did not change (by means of comma positions before and after the cursor). Ref: https://github.com/davidhalter/jedi-vim/pull/420 --- autoload/jedi.vim | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/autoload/jedi.vim b/autoload/jedi.vim index b3fc785..9973a76 100644 --- a/autoload/jedi.vim +++ b/autoload/jedi.vim @@ -367,13 +367,47 @@ function! jedi#do_popup_on_dot_in_highlight() endfunc +let s:show_call_signatures_last = [0, 0, ''] +function! jedi#show_call_signatures() + let [line, col] = [line('.'), col('.')] + let curline = getline(line) + let reload_signatures = 1 + + " Caching. On the same line only. + if line == s:show_call_signatures_last[0] + " Check if the number of commas before or after the cursor has + " not changed: this means that the argument position was not + " changed and we can skip repainting. + let prevcol = s:show_call_signatures_last[1] + let prevline = s:show_call_signatures_last[2] + if substitute(curline[:col-2], '[^,]', '', 'g') + \ == substitute(prevline[:prevcol-2], '[^,]', '', 'g') + \ && substitute(curline[(col-2):], '[^,]', '', 'g') + \ == substitute(prevline[(prevcol-2):], '[^,]', '', 'g') + let reload_signatures = 0 + endif + endif + let s:show_call_signatures_last = [line, col, curline] + + if reload_signatures + PythonJedi jedi_vim.show_call_signatures() + endif +endfunction + + +function! jedi#clear_call_signatures() + let s:show_call_signatures_last = [0, 0, ''] + PythonJedi jedi_vim.clear_call_signatures() +endfunction + + function! jedi#configure_call_signatures() augroup jedi_call_signatures au! if g:jedi#show_call_signatures == 2 " Command line call signatures autocmd InsertEnter let g:jedi#first_col = s:save_first_col() endif - autocmd InsertLeave PythonJedi jedi_vim.clear_call_signatures() + autocmd InsertLeave call jedi#clear_call_signatures() if g:jedi#show_call_signatures_delay > 0 autocmd InsertEnter let b:_jedi_orig_updatetime = &updatetime \ | let &updatetime = g:jedi#show_call_signatures_delay @@ -381,9 +415,9 @@ function! jedi#configure_call_signatures() \ | let &updatetime = b:_jedi_orig_updatetime \ | unlet b:_jedi_orig_updatetime \ | endif - autocmd CursorHoldI PythonJedi jedi_vim.show_call_signatures() + autocmd CursorHoldI call jedi#show_call_signatures() else - autocmd CursorMovedI PythonJedi jedi_vim.show_call_signatures() + autocmd CursorMovedI call jedi#show_call_signatures() endif augroup END endfunction