diff --git a/autoload/vimspector.vim b/autoload/vimspector.vim index 96d3c63..942128a 100644 --- a/autoload/vimspector.vim +++ b/autoload/vimspector.vim @@ -29,6 +29,10 @@ function! vimspector#Launch() abort py3 _vimspector_session.Start() endfunction +function! vimspector#Restart() abort + py3 _vimspector_session.Restart() +endfunction + function! vimspector#ToggleBreakpoint() abort py3 _vimspector_session.ToggleBreakpoint() endfunction diff --git a/autoload/vimspector/internal/job.vim b/autoload/vimspector/internal/job.vim index 1852222..ce79553 100644 --- a/autoload/vimspector/internal/job.vim +++ b/autoload/vimspector/internal/job.vim @@ -95,10 +95,8 @@ function! vimspector#internal#job#StartDebugSession( config ) abort endfunction function! vimspector#internal#job#StopDebugSession() abort - py3 _vimspector_session.Stop() - if job_status( s:job ) == 'run' - job_stop( s:job, 'term' ) + call job_stop( s:job, 'term' ) endif unlet s:job diff --git a/python3/vimspector/code.py b/python3/vimspector/code.py index d4d6e20..8a90acc 100644 --- a/python3/vimspector/code.py +++ b/python3/vimspector/code.py @@ -45,8 +45,9 @@ class CodeView( object ): vim.command( 'nnoremenu WinBar.Finish :call vimspector#StepOut()' ) vim.command( 'nnoremenu WinBar.Pause :call vimspector#Pause()' ) vim.command( 'nnoremenu WinBar.Stop :call vimspector#Stop()' ) + vim.command( 'nnoremenu WinBar.Restart :call vimspector#Restart()' ) - vim.command( 'sign define vimspectorPC text=> texthl=Search' ) + vim.command( 'sign define vimspectorPC text=-> texthl=Search' ) def SetCurrentFrame( self, frame ): diff --git a/python3/vimspector/debug_session.py b/python3/vimspector/debug_session.py index 271fb6f..26a407e 100644 --- a/python3/vimspector/debug_session.py +++ b/python3/vimspector/debug_session.py @@ -50,8 +50,8 @@ class DebugSession( object ): self._breakpoints = defaultdict( dict ) self._configuration = None - vim.command( 'sign define vimspectorBP text=o texthl=Error' ) - vim.command( 'sign define vimspectorBPDisabled text=! texthl=Warning' ) + vim.command( 'sign define vimspectorBP text==> texthl=Error' ) + vim.command( 'sign define vimspectorBPDisabled text=!> texthl=Warning' ) def ToggleBreakpoint( self ): # TODO: Move this to the code view. Problem is that CodeView doesn't exist @@ -59,6 +59,9 @@ class DebugSession( object ): line, column = vim.current.window.cursor file_name = vim.current.buffer.name + if not file_name: + return + if line in self._breakpoints[ file_name ]: bp = self._breakpoints[ file_name ][ line ] if bp[ 'state' ] == 'ENABLED': @@ -101,22 +104,32 @@ class DebugSession( object ): self._configuration = launch_config[ configuration ] - self._StartDebugAdapter() - self._Initialise() - self._SetUpUI() + def start(): + self._StartDebugAdapter() + self._Initialise() + + if not self._uiTab: + self._SetUpUI() + else: + vim.current.tabpage = self._uiTab + self._stackTraceView._connection = self._connection + self._variablesView._connection = self._connection + + if self._connection: + self._StopDebugAdapter( start ) + return + + start() + + def Restart( self ): + # TODO: There is a restart message but isn't always supported. + self.Start() def OnChannelData( self, data ): self._connection.OnData( data ) def Stop( self ): - self._codeView.Clear() - - self._connection.DoRequest( None, { - 'command': 'disconnect', - 'arguments': { - 'terminateDebugee': True - }, - } ) + self._StopDebugAdapter() def StepOver( self ): self._connection.DoRequest( None, { @@ -217,8 +230,25 @@ class DebugSession( object ): self._logger.info( 'Debug Adapter Started' ) + def _StopDebugAdapter( self, callback = None ): + self._codeView.Clear() + + def handler( message ): + vim.eval( 'vimspector#internal#job#StopDebugSession()' ) + self._connection = None + if callback: + callback() + + self._connection.DoRequest( handler, { + 'command': 'disconnect', + 'arguments': { + 'terminateDebugee': True + }, + } ) + def _Initialise( self ): + # TODO: name is mandatory. forcefully add it self._connection.DoRequest( None, { 'command': 'initialize', 'arguments': { @@ -228,6 +258,9 @@ class DebugSession( object ): 'pathFormat': 'path', }, } ) + if 'name' not in self._configuration[ 'configuration' ]: + self._configuration[ 'configuration' ][ 'name' ] = 'test' + self._connection.DoRequest( None, { 'command': self._configuration[ 'configuration' ][ 'request' ], 'arguments': self._configuration[ 'configuration' ]