diff --git a/autoload/vimspector.vim b/autoload/vimspector.vim index 82514bf..97621db 100644 --- a/autoload/vimspector.vim +++ b/autoload/vimspector.vim @@ -19,16 +19,18 @@ let s:save_cpo = &cpo set cpo&vim " }}} - py3 << EOF -from vimspector import debug_session -_vimspector_session = debug_session.DebugSession() -EOF + +call vimspector#internal#state#Reset() " TODO: Test function function! vimspector#Launch() abort py3 _vimspector_session.Start() endfunction +function! vimspector#Reset() abort + py3 _vimspector_session.Reset() +endfunction + function! vimspector#Restart() abort py3 _vimspector_session.Restart() endfunction diff --git a/autoload/vimspector/internal/job.vim b/autoload/vimspector/internal/job.vim index 0def914..da29434 100644 --- a/autoload/vimspector/internal/job.vim +++ b/autoload/vimspector/internal/job.vim @@ -103,6 +103,12 @@ function! vimspector#internal#job#StopDebugSession() abort unlet s:job endfunction +function! vimspector#internal#job#Reset() abort + if exists( 's:job' ) + call vimspector#internal#job#StopDebugSession() + endif +endfunction + " Boilerplate {{{ let &cpo=s:save_cpo unlet s:save_cpo diff --git a/autoload/vimspector/internal/state.vim b/autoload/vimspector/internal/state.vim new file mode 100644 index 0000000..0861a6a --- /dev/null +++ b/autoload/vimspector/internal/state.vim @@ -0,0 +1,32 @@ +" vimspector - A multi-language debugging system for Vim +" Copyright 2018 Ben Jackson +" +" Licensed under the Apache License, Version 2.0 (the "License"); +" you may not use this file except in compliance with the License. +" You may obtain a copy of the License at +" +" http://www.apache.org/licenses/LICENSE-2.0 +" +" Unless required by applicable law or agreed to in writing, software +" distributed under the License is distributed on an "AS IS" BASIS, +" WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +" See the License for the specific language governing permissions and +" limitations under the License. + + +" Boilerplate {{{ +let s:save_cpo = &cpo +set cpo&vim +" }}} + +function! vimspector#internal#state#Reset() + py3 << EOF +from vimspector import debug_session +_vimspector_session = debug_session.DebugSession() +EOF +endfunction + +" Boilerplate {{{ +let &cpo=s:save_cpo +unlet s:save_cpo +" }}} diff --git a/python3/vimspector/code.py b/python3/vimspector/code.py index 8a90acc..03f5420 100644 --- a/python3/vimspector/code.py +++ b/python3/vimspector/code.py @@ -46,6 +46,7 @@ class CodeView( object ): 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( 'nnoremenu WinBar.Reset :call vimspector#Reset()' ) vim.command( 'sign define vimspectorPC text=-> texthl=Search' ) @@ -82,6 +83,8 @@ class CodeView( object ): vim.command( 'sign unplace {0}'.format( self._signs[ 'vimspectorPC' ] ) ) self._signs[ 'vimspectorPC' ] = None + self._UndisplaySigns() + # TODO: You know what, move breakpoint handling out of here into its own # thing. It really doesn't directly relate to the code view. def AddBreakpoints( self, source, breakpoints ): diff --git a/python3/vimspector/debug_session.py b/python3/vimspector/debug_session.py index 9260b4b..39edeb4 100644 --- a/python3/vimspector/debug_session.py +++ b/python3/vimspector/debug_session.py @@ -40,6 +40,8 @@ class DebugSession( object ): self._uiTab = None self._threadsBuffer = None self._outputBuffer = None + self._stackTraceView = None + self._variablesView = None self._currentThread = None self._currentFrame = None @@ -137,6 +139,24 @@ class DebugSession( object ): def Stop( self ): self._StopDebugAdapter() + def Reset( self ): + if self._connection: + self._StopDebugAdapter( lambda: self._Reset() ) + else: + self._Reset() + + def _Reset( self ): + self._RemoveBreakpoints() + + if self._uiTab: + self._stackTraceView.Reset() + self._variablesView.Reset() + vim.current.tabpage = self._uiTab + vim.command( 'tabclose' ) + + vim.eval( 'vimspector#internal#job#Reset()' ) + vim.eval( 'vimspector#internal#state#Reset()' ) + def StepOver( self ): self._connection.DoRequest( None, { 'command': 'next', @@ -314,16 +334,25 @@ class DebugSession( object ): 'Unrecognised breakpoint event (undocumented): {0}'.format( reason ), persist = True ) + def Clear( self ): + self._codeView.Clear() + self._stackTraceView.Clear() + self._variablesView.Clear() + with utils.ModifiableScratchBuffer( self._threadsBuffer ): + self._threadsBuffer[:] = None + def OnEvent_terminated( self, message ): utils.UserMessage( "The program was terminated because: {0}".format( message.get( 'body', {} ).get( 'reason', "No specific reason" ) ) ) - self._codeView.Clear() - self._stackTraceView.Clear() - self._variablesView.Clear() + self.Clear() - with utils.ModifiableScratchBuffer( self._threadsBuffer ): - self._threadsBuffer[:] = None + def _RemoveBreakpoints( self ): + for file_name, line_breakpoints in self._breakpoints.items(): + for line, bp in line_breakpoints.items(): + if 'sign_id' in bp: + vim.command( 'sign unplace {0}'.format( bp[ 'sign_id' ] ) ) + del bp[ 'sign_id' ] def _SendBreakpoints( self ): for file_name, line_breakpoints in self._breakpoints.items(): diff --git a/python3/vimspector/stack_trace.py b/python3/vimspector/stack_trace.py index 4cd790b..f67b929 100644 --- a/python3/vimspector/stack_trace.py +++ b/python3/vimspector/stack_trace.py @@ -38,6 +38,10 @@ class StackTraceView( object ): self.Clear() self._connection = None + def Reset( self ): + self.Clear() + # TODO: delete the buffer ? + def LoadStackTrace( self, thread_id ): self._connection.DoRequest( self._PrintStackTrace, { 'command': 'stackTrace', diff --git a/python3/vimspector/variables.py b/python3/vimspector/variables.py index 517d670..89261c9 100644 --- a/python3/vimspector/variables.py +++ b/python3/vimspector/variables.py @@ -51,6 +51,13 @@ class VariablesView( object ): utils.SetUpScratchBuffer( self._buf, 'vimspector.Variables' ) + self._oldoptions = { + 'balloonexpr': vim.options[ 'balloonexpr' ], + 'ballooneval': vim.options[ 'ballooneval' ], + 'balloonevalterm': vim.options[ 'balloonevalterm' ], + 'balloondelay': vim.options[ 'balloondelay' ], + } + vim.options[ 'balloonexpr' ] = 'vimspector#internal#balloon#BalloonExpr()' vim.options[ 'ballooneval' ] = True vim.options[ 'balloonevalterm' ] = True @@ -64,6 +71,12 @@ class VariablesView( object ): self.Clear() self._connection = None + def Reset( self ): + for k, v in self._oldoptions.items(): + vim.options[ k ] = v + + # TODO: delete the buffer? + def LoadScopes( self, frame ): def scopes_consumer( message ): self._scopes = []