Fix handling data after exit - channels and neovim

This commit is contained in:
Ben Jackson 2020-07-11 14:07:28 +01:00
commit 43dd282702
3 changed files with 39 additions and 5 deletions

View file

@ -20,12 +20,20 @@ set cpoptions&vim
" }}}
function! s:_OnServerData( channel, data ) abort
if !exists( 's:ch' ) || s:ch isnot a:channel
return
endif
py3 << EOF
_vimspector_session.OnChannelData( vim.eval( 'a:data' ) )
EOF
endfunction
function! s:_OnClose( channel ) abort
if !exists( 's:ch' ) || s:ch isnot a:channel
return
endif
echom 'Channel closed'
redraw
unlet s:ch

View file

@ -22,6 +22,14 @@ set cpoptions&vim
function! s:_OnEvent( chan_id, data, event ) abort
if v:exiting isnot# v:null
return
endif
if !exists( 's:ch' ) || a:chan_id != s:ch
return
endif
if a:data == ['']
echom 'Channel closed'
redraw

View file

@ -22,6 +22,14 @@ set cpoptions&vim
function! s:_OnEvent( chan_id, data, event ) abort
if v:exiting isnot# v:null
return
endif
if !exists( 's:job' ) || a:chan_id != s:job
return
endif
" In neovim, the data argument is a list.
if a:event ==# 'stdout'
py3 _vimspector_session.OnChannelData( '\n'.join( vim.eval( 'a:data' ) ) )
@ -30,9 +38,7 @@ function! s:_OnEvent( chan_id, data, event ) abort
elseif a:event ==# 'exit'
echom 'Channel exit with status ' . a:data
redraw
if exists( 's:job' )
unlet s:job
endif
unlet s:job
" This causes terminal spam in neovim due to
" https://github.com/neovim/neovim/issues/11725
py3 _vimspector_session.OnServerExit( vim.eval( 'a:data' ) )
@ -108,10 +114,22 @@ function! vimspector#internal#neojob#Reset() abort
endfunction
function! s:_OnCommandEvent( category, id, data, event ) abort
if v:exiting isnot# v:null
return
endif
if a:data == ['']
return
endif
if !has_key( s:commands, a:category )
return
endif
if !has_key( s:commands[ a:category ], a:id )
return
endif
if a:event ==# 'stdout'
let buffer = s:commands[ a:category ][ a:id ].stdout
elseif a:event ==# 'stderr'
@ -212,8 +230,8 @@ function! vimspector#internal#neojob#CleanUpCommand( category ) abort
endif
for id in keys( s:commands[ a:category ] )
call jobstop( id )
call jobwait( id )
call jobstop( str2nr( id ) )
call jobwait( [ str2nr( id ) ] )
endfor
unlet! s:commands[ a:category ]
endfunction