preservim / tagbar

Vim plugin that displays tags in a window, ordered by scope
https://preservim.github.io/tagbar
Other
6.11k stars 486 forks source link

suggest let s:AutoUpdate function run async #532

Open pangchol opened 5 years ago

pangchol commented 5 years ago

I use tagbar to repacle taglist recently, but I find when I use vim-rtags to jump anohter file, or edist a file, if this file is open first time , the main windows screen will often refreash unnecessary. soon I find it is cause by s:AutoUpdate always jump to tagbrer windows first and then jump back , this flow is by in sync and the " autocmd BufEnter " auto call s:AutoUpdate at the buffer not be completely ready. so I try using job_start to let s:AutoUpdate Call async and find the refreash disappear. my simple implementation like this:

function! s:AutoUpdate(fname, force, ...) abort
    let g:tagbar_update_fname = a:fname
    let g:tagbar_update_force = a:force
    let g:tagbar_no_display = a:0 > 0 ? a:1 : 0
    call job_start('sleep 0', {'close_cb':'AutoUpdate_CB'})
endfunc

function! AutoUpdate_CB(channel) abort
    " call tagbar#debug#log('AutoUpdate called [' . fname . ']')
    let fname = g:tagbar_update_fname
    let force = g:tagbar_update_force
    let no_display = g:tagbar_no_display

the AutoUpdate_CB is the old s:AutoUpdate function and just modify the three line ahead.

alerque commented 4 years ago

Thanks for noting this @pangchol. This would probably be a really good thing to include out of the box. Would you care to whip up a PR for it?

Also can anybody comment on the status of async support right now? Does this need a different command for vim vs. neovim? Do we need to check that async support is included at all? I'm guessing we might need a three way check here to implement it right: ① old vim without async, ② new vim with async, and ③ neovim.