From 0140a607b1b6f6abd43eb87edcf55eac84166b92 Mon Sep 17 00:00:00 2001 From: Ben Jackson Date: Tue, 21 Jul 2020 19:11:31 +0100 Subject: [PATCH] Raise autocommand when installer completes. use this in testing --- autoload/vimspector/internal/job.vim | 11 ++++++++++ python3/vimspector/installer.py | 28 ++++++++++++++++++------- python3/vimspector/output.py | 31 +++++++++++++++------------- python3/vimspector/utils.py | 15 +++++++++++++- run_tests | 23 +++++++++++++++++++-- 5 files changed, 84 insertions(+), 24 deletions(-) diff --git a/autoload/vimspector/internal/job.vim b/autoload/vimspector/internal/job.vim index 834f83c..51ed137 100644 --- a/autoload/vimspector/internal/job.vim +++ b/autoload/vimspector/internal/job.vim @@ -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' diff --git a/python3/vimspector/installer.py b/python3/vimspector/installer.py index 29ae91f..eefbd80 100644 --- a/python3/vimspector/installer.py +++ b/python3/vimspector/installer.py @@ -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( { diff --git a/python3/vimspector/output.py b/python3/vimspector/output.py index 2e2412b..4b89d95 100644 --- a/python3/vimspector/output.py +++ b/python3/vimspector/output.py @@ -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 ) diff --git a/python3/vimspector/utils.py b/python3/vimspector/utils.py index ab6f733..cf4a69d 100644 --- a/python3/vimspector/utils.py +++ b/python3/vimspector/utils.py @@ -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 ) diff --git a/run_tests b/run_tests index c03c7b9..3c327bb 100755 --- a/run_tests +++ b/run_tests @@ -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