diff --git a/python3/vimspector/code.py b/python3/vimspector/code.py index 724bffb..058e986 100644 --- a/python3/vimspector/code.py +++ b/python3/vimspector/code.py @@ -104,6 +104,8 @@ class CodeView( object ): self._logger.debug( 'Breakpoints at this point: {0}'.format( json.dumps( self._breakpoints, indent = 2 ) ) ) + self.ShowBreakpoints() + def UpdateBreakpoint( self, bp ): if 'id' not in bp: self.AddBreakpoints( None, [ bp ] ) @@ -112,6 +114,7 @@ class CodeView( object ): for index, breakpoint in enumerate( breakpoint_list ): if 'id' in breakpoint and breakpoint[ 'id' ] == bp[ 'id' ]: breakpoint_list[ index ] = bp + self.ShowBreakpoints() return # Not found. Assume new diff --git a/python3/vimspector/debug_session.py b/python3/vimspector/debug_session.py index cc1d83a..1acbc7b 100644 --- a/python3/vimspector/debug_session.py +++ b/python3/vimspector/debug_session.py @@ -51,7 +51,7 @@ class DebugSession( object ): # leading to them getting out of sync # - the split of responsibility between this object and the CodeView is # messy and ill-defined. - self._breakpoints = defaultdict( dict ) + self._line_breakpoints = defaultdict( list ) self._configuration = None vim.command( 'sign define vimspectorBP text==> texthl=Error' ) @@ -64,21 +64,28 @@ class DebugSession( object ): if not file_name: return - if line in self._breakpoints[ file_name ]: - bp = self._breakpoints[ file_name ][ line ] - if bp[ 'state' ] == 'ENABLED': - bp[ 'state' ] = 'DISABLED' - else: - if 'sign_id' in bp: - vim.command( 'sign unplace {0}'.format( bp[ 'sign_id' ] ) ) - del self._breakpoints[ file_name ][ line ] - else: - self._breakpoints[ file_name ][ line ] = { + found_bp = False + for index, bp in enumerate( self._line_breakpoints[ file_name] ): + if bp[ 'line' ] == line: + found_bp = True + if bp[ 'state' ] == 'ENABLED': + bp[ 'state' ] = 'DISABLED' + else: + if 'sign_id' in bp: + vim.command( 'sign unplace {0}'.format( bp[ 'sign_id' ] ) ) + del self._line_breakpoints[ file_name ][ index ] + + if not found_bp: + self._line_breakpoints[ file_name ].append( { 'state': 'ENABLED', + 'line': line, + # 'sign_id': , + # + # Used by other breakpoint types: # 'condition': ..., # 'hitCondition': ..., # 'logMessage': ... - } + } ) if self._connection: self._SendBreakpoints() @@ -389,6 +396,8 @@ class DebugSession( object ): 'command': 'configurationDone', } ) + self._stackTraceView.LoadThreads( True ) + def OnEvent_thread( self, message ): if message[ 'body' ][ 'reason' ] == 'started': pass @@ -421,8 +430,8 @@ class DebugSession( object ): self.Clear() def _RemoveBreakpoints( self ): - for file_name, line_breakpoints in self._breakpoints.items(): - for line, bp in line_breakpoints.items(): + for breakpoints in self._line_breakpoints.values(): + for bp in breakpoints: if 'sign_id' in bp: vim.command( 'sign unplace {0}'.format( bp[ 'sign_id' ] ) ) del bp[ 'sign_id' ] @@ -430,10 +439,9 @@ class DebugSession( object ): def _SendBreakpoints( self ): self._codeView.ClearBreakpoints() - for file_name, line_breakpoints in self._breakpoints.items(): + for file_name, line_breakpoints in self._line_breakpoints.items(): breakpoints = [] - lines = [] - for line, bp in line_breakpoints.items(): + for bp in line_breakpoints: if bp[ 'state' ] != 'ENABLED': continue @@ -441,8 +449,7 @@ class DebugSession( object ): vim.command( 'sign unplace {0}'.format( bp[ 'sign_id' ] ) ) del bp[ 'sign_id' ] - breakpoints.append( { 'line': line } ) - lines.append( line ) + breakpoints.append( { 'line': bp[ 'line' ] } ) source = { 'name': os.path.basename( file_name ), @@ -455,16 +462,15 @@ class DebugSession( object ): 'command': 'setBreakpoints', 'arguments': { 'source': source, - 'breakpoints': breakpoints + 'breakpoints': breakpoints, }, - 'lines': lines, 'sourceModified': False, # TODO: We can actually check this } ) def _ShowBreakpoints( self ): - for file_name, line_breakpoints in self._breakpoints.items(): - for line, bp in line_breakpoints.items(): + for file_name, line_breakpoints in self._line_breakpoints.items(): + for bp in line_breakpoints: if 'sign_id' in bp: vim.command( 'sign unplace {0}'.format( bp[ 'sign_id' ] ) ) else: @@ -474,7 +480,7 @@ class DebugSession( object ): vim.command( 'sign place {0} line={1} name={2} file={3}'.format( bp[ 'sign_id' ] , - line, + bp[ 'line' ], 'vimspectorBP' if bp[ 'state' ] == 'ENABLED' else 'vimspectorBPDisabled', file_name ) ) diff --git a/python3/vimspector/output.py b/python3/vimspector/output.py index 4efce34..5aa50ba 100644 --- a/python3/vimspector/output.py +++ b/python3/vimspector/output.py @@ -51,15 +51,14 @@ class OutputView( object ): with utils.RestorCurrentWindow(): vim.current.window = self._window - vim.command( 'enew' ) - self._buffers[ category ] = vim.current.buffer - self._buffers[ category ].append( category + '-----' ) + with utils.RestoreCurrentBuffer( self._window ): + vim.command( 'enew' ) + self._buffers[ category ] = vim.current.buffer + self._buffers[ category ].append( category + '-----' ) - utils.SetUpHiddenBuffer( self._buffers[ category ], - 'vimspector.Output:{0}'.format( category ) ) + utils.SetUpHiddenBuffer( self._buffers[ category ], + 'vimspector.Output:{0}'.format( category ) ) - vim.command( "nnoremenu WinBar.{0} " - ":call vimspector#ShowOutput( '{0}' )".format( - utils.Escape( category ) ) ) - - vim.command( 'bu #' ) + vim.command( "nnoremenu WinBar.{0} " + ":call vimspector#ShowOutput( '{0}' )".format( + utils.Escape( category ) ) ) diff --git a/python3/vimspector/stack_trace.py b/python3/vimspector/stack_trace.py index 3c6ac7f..28333ee 100644 --- a/python3/vimspector/stack_trace.py +++ b/python3/vimspector/stack_trace.py @@ -122,7 +122,8 @@ class StackTraceView( object ): thread = self._line_to_thread[ current_line ] if '_frames' in thread: del thread[ '_frames' ] - self._DrawThreads() + with utils.RestoreCursorPosition(): + self._DrawThreads() else: self._LoadStackTrace( thread, False ) diff --git a/python3/vimspector/utils.py b/python3/vimspector/utils.py index 3bd1270..36a9971 100644 --- a/python3/vimspector/utils.py +++ b/python3/vimspector/utils.py @@ -84,11 +84,13 @@ def RestorCurrentWindow(): @contextlib.contextmanager def RestoreCurrentBuffer( window ): - old_buffer_name = window.buffer.name + old_buffer = window.buffer try: yield finally: - window.buffer.name = old_buffer_name + with RestorCurrentWindow(): + vim.current.window = window + vim.current.buffer = old_buffer @contextlib.contextmanager