Skip to content

Commit

Permalink
🐛 Do NOT invoke RPC functions directly from components
Browse files Browse the repository at this point in the history
Otherwise components cause this kind of issues.

Shougo/ddu.vim#14
  • Loading branch information
lambdalisue committed Apr 1, 2022
1 parent fe45b9e commit be2a02a
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 21 deletions.
29 changes: 22 additions & 7 deletions autoload/gin/component/branch.vim
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
let s:ascii = ''
let s:unicode = ''

function! gin#component#branch#ascii(...) abort
let cwd = a:0 ? a:1 : ''
call timer_start(0, { -> s:update_ascii(cwd) })
return s:ascii
endfunction

function! gin#component#branch#unicode(...) abort
let cwd = a:0 ? a:1 : ''
call timer_start(0, { -> s:update_unicode(cwd) })
return s:unicode
endfunction

function! s:update_ascii(cwd) abort
try
let cwd = a:0 ? a:1 : ''
return denops#request('gin', 'component:branch:ascii', [cwd])
let s:ascii = denops#request('gin', 'component:branch:ascii', [a:cwd])
catch
return ""
let s:ascii = ''
endtry
call gin#util#redraw_components()
endfunction

function! gin#component#branch#unicode(...) abort
function! s:update_unicode(cwd) abort
try
let cwd = a:0 ? a:1 : ''
return denops#request('gin', 'component:branch:unicode', [cwd])
let s:unicode = denops#request('gin', 'component:branch:unicode', [a:cwd])
catch
return ""
let s:unicode = ''
endtry
call gin#util#redraw_components()
endfunction
29 changes: 22 additions & 7 deletions autoload/gin/component/traffic.vim
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
let s:ascii = ''
let s:unicode = ''

function! gin#component#traffic#ascii(...) abort
let cwd = a:0 ? a:1 : ''
call timer_start(0, { -> s:update_ascii(cwd) })
return s:ascii
endfunction

function! gin#component#traffic#unicode(...) abort
let cwd = a:0 ? a:1 : ''
call timer_start(0, { -> s:update_unicode(cwd) })
return s:unicode
endfunction

function! s:update_ascii(cwd) abort
try
let cwd = a:0 ? a:1 : ''
return denops#request('gin', 'component:traffic:ascii', [cwd])
let s:ascii = denops#request('gin', 'component:traffic:ascii', [a:cwd])
catch
return ""
let s:ascii = ''
endtry
call gin#util#redraw_components()
endfunction

function! gin#component#traffic#unicode(...) abort
function! s:update_unicode(cwd) abort
try
let cwd = a:0 ? a:1 : ''
return denops#request('gin', 'component:traffic:unicode', [cwd])
let s:unicode = denops#request('gin', 'component:traffic:unicode', [a:cwd])
catch
return ""
let s:unicode = ''
endtry
call gin#util#redraw_components()
endfunction
29 changes: 22 additions & 7 deletions autoload/gin/component/worktree.vim
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
let s:name = ''
let s:full = ''

function! gin#component#worktree#full(...) abort
let cwd = a:0 ? a:1 : ''
call timer_start(0, { -> s:update_full(cwd) })
return s:full
endfunction

function! gin#component#worktree#name(...) abort
let cwd = a:0 ? a:1 : ''
call timer_start(0, { -> s:update_name(cwd) })
return s:name
endfunction

function! s:update_name(cwd) abort
try
let cwd = a:0 ? a:1 : ''
return denops#request('gin', 'component:worktree:full', [cwd])
let s:name = denops#request('gin', 'component:worktree:name', [a:cwd])
catch
return ""
let s:name = ''
endtry
call gin#util#redraw_components()
endfunction

function! gin#component#worktree#name(...) abort
function! s:update_full(cwd) abort
try
let cwd = a:0 ? a:1 : ''
return denops#request('gin', 'component:worktree:name', [cwd])
let s:full = denops#request('gin', 'component:worktree:full', [a:cwd])
catch
return ""
let s:full = ''
endtry
call gin#util#redraw_components()
endfunction
12 changes: 12 additions & 0 deletions autoload/gin/util.vim
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
let s:redraw_component_timer = 0

function! gin#util#reload(...) abort
let bufnr = a:0 ? a:1 : bufnr()
call denops#plugin#wait('gin')
Expand All @@ -8,3 +10,13 @@ function! gin#util#expand(expr) abort
call denops#plugin#wait('gin')
return denops#request('gin', 'util:expand', [a:expr])
endfunction

function! gin#util#redraw_components() abort
silent! call timer_stop(s:redraw_component_timer)
let s:redraw_component_timer = timer_start(
\ g:gin#util#redraw_components_delay,
\ { -> execute('redrawstatus | redrawtabline') },
\)
endfunction

let g:gin#util#redraw_components_delay = get(g:, 'gin#util#redraw_components_delay', 100)

0 comments on commit be2a02a

Please sign in to comment.