Add a reset command to undo all the UI and reset everything

This commit is contained in:
Ben Jackson 2018-05-27 21:34:44 +01:00
commit 7600e1e652
7 changed files with 98 additions and 9 deletions

View file

@ -46,6 +46,7 @@ class CodeView( object ):
vim.command( 'nnoremenu WinBar.Pause :call vimspector#Pause()<CR>' )
vim.command( 'nnoremenu WinBar.Stop :call vimspector#Stop()<CR>' )
vim.command( 'nnoremenu WinBar.Restart :call vimspector#Restart()<CR>' )
vim.command( 'nnoremenu WinBar.Reset :call vimspector#Reset()<CR>' )
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 ):

View file

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

View file

@ -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',

View file

@ -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 = []