Raise autocommand when installer completes. use this in testing

This commit is contained in:
Ben Jackson 2020-07-21 19:11:31 +01:00
commit 0140a607b1
5 changed files with 84 additions and 24 deletions

View file

@ -146,6 +146,14 @@ function! vimspector#internal#job#Reset() abort
call vimspector#internal#job#StopDebugSession()
endfunction
function! s:_OnCommandExit( category, ch, code ) abort
py3 << EOF
from vimspector import utils as vimspector_utils
vimspector_utils.OnCommandWithLogComplete( vim.eval( 'a:category' ),
int( vim.eval( 'a:code' ) ) )
EOF
endfunction
function! vimspector#internal#job#StartCommandWithLog( cmd, category ) abort
if ! exists( 's:commands' )
let s:commands = {}
@ -165,8 +173,11 @@ function! vimspector#internal#job#StartCommandWithLog( cmd, category ) abort
\ 'out_io': 'buffer',
\ 'in_io': 'null',
\ 'err_io': 'buffer',
\ 'out_msg': 0,
\ 'err_msg': 0,
\ 'out_name': buf,
\ 'err_name': buf,
\ 'exit_cb': funcref( 's:_OnCommandExit', [ a:category ] ),
\ 'out_modifiable': 0,
\ 'err_modifiable': 0,
\ 'stoponexit': 'kill'

View file

@ -107,10 +107,22 @@ def RunInstaller( api_prefix, *args ):
'--update-gadget-config',
]
if not vimspector_base_dir == vimspector_home:
cmd.extend( '--basedir', vimspector_base_dir )
cmd.extend( [ '--basedir', vimspector_base_dir ] )
cmd.extend( args )
OUTPUT_VIEW.RunJobWithOutput( 'Installer', cmd )
def handler( exit_code ):
if exit_code == 0:
utils.UserMessage( "Vimspector installation complete!" )
vim.command( 'doautocmd User VimspectorInstallSuccess' )
else:
utils.UserMessage( 'Vimspector installation reported errors',
error = True )
vim.command( 'silent doautocmd User VimspectorInstallFailed' )
OUTPUT_VIEW.RunJobWithOutput( 'Installer',
cmd,
completion_handler = handler )
OUTPUT_VIEW.ShowOutput( 'Installer' )
@ -309,12 +321,14 @@ def InstallGagdet( name, gadget, succeeded, failed, all_adapters ):
def ReadAdapters( read_existing = True ):
all_adapters = {}
if read_existing:
with open( install.GetGadgetConfigFile( options.vimspector_base ),
'r' ) as f:
all_adapters = json.load( f ).get( 'adapters', {} )
else:
all_adapters = {}
try:
with open( install.GetGadgetConfigFile( options.vimspector_base ),
'r' ) as f:
all_adapters = json.load( f ).get( 'adapters', {} )
except OSError:
pass
# Include "built-in" adapter for multi-session mode
all_adapters.update( {

View file

@ -92,18 +92,11 @@ class OutputView( object ):
VIEWS.remove( self )
def _CleanUpBuffer( self, category, tab_buffer = None ):
if tab_buffer is None:
tab_buffer = self._buffers[ category ]
if tab_buffer.is_job:
utils.CleanUpCommand( category, self._api_prefix )
utils.CleanUpHiddenBuffer( tab_buffer.buf )
def Clear( self ):
for category, tab_buffer in self._buffers.items():
self._CleanUpBuffer( category, tab_buffer )
if tab_buffer.is_job:
utils.CleanUpCommand( category, self._api_prefix )
utils.CleanUpHiddenBuffer( tab_buffer.buf )
# FIXME: nunmenu the WinBar ?
self._buffers = {}
@ -140,11 +133,17 @@ class OutputView( object ):
self._RenderWinBar( category )
def RunJobWithOutput( self, category, cmd ):
self._CreateBuffer( category, cmd = cmd )
def RunJobWithOutput( self, category, cmd, completion_handler = None ):
self._CreateBuffer( category,
cmd = cmd,
completion_handler = completion_handler )
def _CreateBuffer( self, category, file_name = None, cmd = None ):
def _CreateBuffer( self,
category,
file_name = None,
cmd = None,
completion_handler = None ):
win = self._window
if not win.valid:
# We need to borrow the current window
@ -162,7 +161,11 @@ class OutputView( object ):
cmd = [ 'tail', '-F', '-n', '+1', '--', file_name ]
if cmd is not None:
out = utils.SetUpCommandBuffer( cmd, category, self._api_prefix )
out = utils.SetUpCommandBuffer(
cmd,
category,
self._api_prefix,
completion_handler = completion_handler )
self._buffers[ category ] = TabBuffer( out, len( self._buffers ) )
self._buffers[ category ].is_job = True
self._RenderWinBar( category )

View file

@ -71,7 +71,20 @@ def OpenFileInCurrentWindow( file_name ):
return vim.buffers[ buffer_number ]
def SetUpCommandBuffer( cmd, name, api_prefix ):
COMMAND_HANDLERS = {}
def OnCommandWithLogComplete( name, exit_code ):
cb = COMMAND_HANDLERS.get( name )
if cb:
cb( exit_code )
else:
UserMessage( f'Job complete: { name } (exit status: { exit_code })' )
def SetUpCommandBuffer( cmd, name, api_prefix, completion_handler = None ):
COMMAND_HANDLERS[ name ] = completion_handler
buf = Call( f'vimspector#internal#{api_prefix}job#StartCommandWithLog',
cmd,
name )

View file

@ -25,6 +25,11 @@ while [ -n "$1" ]; do
INSTALL=1
shift
;;
"--install-method")
shift
INSTALL=$1
shift
;;
"--report")
shift
VIMSPECTOR_TEST_STDOUT=$1
@ -71,8 +76,22 @@ if [ "${out_fd}" = "1" ]; then
exec 3>&1
fi
if [ $INSTALL = 1 ]; then
python3 $(dirname $0)/install_gadget.py --basedir ${BASEDIR} --all
if [ "$INSTALL" = "1" ] || [ "$INSTALL" = "script" ]; then
if ! python3 $(dirname $0)/install_gadget.py --basedir ${BASEDIR} --all; then
echo "Script installation reported errors" >&2
exit 1
fi
fi
if [ "$INSTALL" = "1" ] || [ "$INSTALL" = "vim" ]; then
if ! $RUN_VIM -u $(dirname $0)/tests/vimrc \
--cmd "${BASEDIR_CMD}" \
-c 'autocmd User VimspectorInstallSuccess qa!' \
-c 'autocmd User VimspectorInstallFailed cquit!' \
-c "VimspectorInstall --all"; then
echo "Vim installation reported errors" >&2
exit 1
fi
fi
if [ -z "$VIMSPECTOR_MIMODE" ]; then