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

@ -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 )