Make sure to close down cleanly

This involves some horrible forceful reading on exit to ensure that we
get a response to the disconnect request. This ensures that any debugee
is killed cleanly.
This commit is contained in:
Ben Jackson 2018-05-28 13:49:40 +01:00
commit eb11712cc1
2 changed files with 38 additions and 1 deletions

View file

@ -67,7 +67,8 @@ function! vimspector#internal#job#StartDebugSession( config ) abort
\ 'exit_cb': function( 's:_OnExit' ),
\ 'close_cb': function( 's:_OnClose' ),
\ 'out_cb': function( 's:_OnServerData' ),
\ 'err_cb': function( 's:_OnServerError' )
\ 'err_cb': function( 's:_OnServerError' ),
\ 'stoponexit': 'term',
\ }
\ )
@ -93,6 +94,15 @@ function! vimspector#internal#job#Reset() abort
endif
endfunction
function! vimspector#internal#job#ForceRead() abort
if exists( 's:job' )
let data = ch_readraw( job_getchannel( s:job ), { 'timeout': 1000 } )
if data != ''
call s:_OnServerData( job_getchannel( s:job ), data )
endif
endif
endfunction
" Boilerplate {{{
let &cpo=s:save_cpo
unlet s:save_cpo

View file

@ -274,9 +274,36 @@ class DebugSession( object ):
self._logger.info( 'Debug Adapter Started' )
vim.command( 'augroup vimspector_cleanup' )
vim.command( 'autocmd!' )
vim.command( 'autocmd VimLeavePre * py3 _vimspector_session.CloseDown()' )
vim.command( 'augroup END' )
def CloseDown( self ):
state = { 'done': False }
def handler( self ):
state[ 'done' ] = True
self._connection.DoRequest( handler, {
'command': 'disconnect',
'arguments': {
'terminateDebugee': True
},
} )
while not state[ 'done' ]:
vim.eval( 'vimspector#internal#job#ForceRead()' )
vim.eval( 'vimspector#internal#job#StopDebugSession()' )
def _StopDebugAdapter( self, callback = None ):
def handler( message ):
vim.eval( 'vimspector#internal#job#StopDebugSession()' )
vim.command( 'au! vimspector_cleanup' )
self._connection.Reset()
self._connection = None
self._stackTraceView.ConnectionClosed()