Skip to content

Commit

Permalink
Use timers for show_call_signatures_delay
Browse files Browse the repository at this point in the history
This appears to fix the issue where CursorHoldI is broken when used with
deoplete etc (neovim/neovim#3757), and is less
hackish in general.
  • Loading branch information
blueyed committed Aug 18, 2019
1 parent fcd11aa commit 135e0b3
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 16 deletions.
54 changes: 41 additions & 13 deletions autoload/jedi.vim
Original file line number Diff line number Diff line change
Expand Up @@ -480,12 +480,35 @@ function! jedi#show_call_signatures() abort
endif
endfunction

function! s:show_call_signatures_delayed_cb(timer) abort
if getpos('.') == s:show_call_signatures_delayed_pos
call jedi#show_call_signatures()
endif
endfunction

function! jedi#show_call_signatures_delayed() abort
if exists('s:show_call_signatures_timer')
call timer_stop(s:show_call_signatures_timer)
endif
" Clear call signatures immediately when changing the line.
if line('.') != s:show_call_signatures_last[0]
call jedi#clear_call_signatures()
endif
let s:show_call_signatures_delayed_pos = getpos('.')
let s:show_call_signatures_timer = timer_start(
\ g:jedi#show_call_signatures_delay,
\ function('s:show_call_signatures_delayed_cb'))
endfunction


function! jedi#clear_call_signatures() abort
if s:_init_python == 0
return 1
endif

if s:show_call_signatures_last[0] == 0
" No call signature displayed currently.
return
endif
let s:show_call_signatures_last = [0, 0, '']
PythonJedi jedi_vim.clear_call_signatures()
endfunction
Expand Down Expand Up @@ -570,19 +593,24 @@ function! jedi#configure_call_signatures(...) abort

autocmd InsertEnter <buffer> let s:show_call_signatures_last = [0, 0, '']
autocmd InsertLeave <buffer> call jedi#clear_call_signatures()

if g:jedi#show_call_signatures_delay > 0
autocmd InsertEnter <buffer> let b:_jedi_orig_updatetime = &updatetime
\ | let &updatetime = g:jedi#show_call_signatures_delay
autocmd InsertLeave <buffer> if exists('b:_jedi_orig_updatetime')
\ | let &updatetime = b:_jedi_orig_updatetime
\ | unlet b:_jedi_orig_updatetime
\ | endif
autocmd CursorHoldI <buffer> call jedi#show_call_signatures()
" Clear signatures immediately when changing lines.
autocmd CursorMovedI <buffer>
\ if line('.') != s:show_call_signatures_last[0]
\ | call jedi#clear_call_signatures()
\ | endif
if has('timers')
autocmd InsertEnter,CursorMovedI <buffer> call jedi#show_call_signatures_delayed()
else
autocmd InsertEnter <buffer> let b:_jedi_orig_updatetime = &updatetime
\ | let &updatetime = g:jedi#show_call_signatures_delay
autocmd InsertLeave <buffer> if exists('b:_jedi_orig_updatetime')
\ | let &updatetime = b:_jedi_orig_updatetime
\ | unlet b:_jedi_orig_updatetime
\ | endif
autocmd CursorHoldI <buffer> call jedi#show_call_signatures()
" Clear signatures immediately when changing lines.
autocmd CursorMovedI <buffer>
\ if line('.') != s:show_call_signatures_last[0]
\ | call jedi#clear_call_signatures()
\ | endif
endif
else
autocmd CursorMovedI <buffer> call jedi#show_call_signatures()
endif
Expand Down
9 changes: 6 additions & 3 deletions doc/jedi-vim.txt
Original file line number Diff line number Diff line change
Expand Up @@ -422,9 +422,12 @@ function directly to change it: >
------------------------------------------------------------------------------
6.7. `g:jedi#show_call_signatures_delay` *g:jedi#show_call_signatures_delay*

The delay to be used with |g:jedi#show_call_signatures|. If it is greater
than 0 it will use Vim's |CursorHoldI| event instead of |CursorMovedI|.
It will temporarily set Vim's |'updatetime'| option during insert mode.
The delay to be used with |g:jedi#show_call_signatures|.
If it is greater than 0 it will use Vim's |+timers| feature to delay the
display of the signature, instead of on |CursorMovedI| directly.

(If |+timers| is not available, a fallback through the |CursorHoldI| event is
used, where Vim's |'updatetime'| option is changed while in insert mode)

Options: delay in milliseconds
Default: 500
Expand Down

0 comments on commit 135e0b3

Please sign in to comment.