Start to refactor breakpoints into different types
This basically stores line breakpoints as a map by file name. Soon to come: function breakpoints and others.
This commit is contained in:
parent
979e796bf4
commit
9baea25c46
5 changed files with 48 additions and 37 deletions
|
|
@ -104,6 +104,8 @@ class CodeView( object ):
|
||||||
self._logger.debug( 'Breakpoints at this point: {0}'.format(
|
self._logger.debug( 'Breakpoints at this point: {0}'.format(
|
||||||
json.dumps( self._breakpoints, indent = 2 ) ) )
|
json.dumps( self._breakpoints, indent = 2 ) ) )
|
||||||
|
|
||||||
|
self.ShowBreakpoints()
|
||||||
|
|
||||||
def UpdateBreakpoint( self, bp ):
|
def UpdateBreakpoint( self, bp ):
|
||||||
if 'id' not in bp:
|
if 'id' not in bp:
|
||||||
self.AddBreakpoints( None, [ bp ] )
|
self.AddBreakpoints( None, [ bp ] )
|
||||||
|
|
@ -112,6 +114,7 @@ class CodeView( object ):
|
||||||
for index, breakpoint in enumerate( breakpoint_list ):
|
for index, breakpoint in enumerate( breakpoint_list ):
|
||||||
if 'id' in breakpoint and breakpoint[ 'id' ] == bp[ 'id' ]:
|
if 'id' in breakpoint and breakpoint[ 'id' ] == bp[ 'id' ]:
|
||||||
breakpoint_list[ index ] = bp
|
breakpoint_list[ index ] = bp
|
||||||
|
self.ShowBreakpoints()
|
||||||
return
|
return
|
||||||
|
|
||||||
# Not found. Assume new
|
# Not found. Assume new
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ class DebugSession( object ):
|
||||||
# leading to them getting out of sync
|
# leading to them getting out of sync
|
||||||
# - the split of responsibility between this object and the CodeView is
|
# - the split of responsibility between this object and the CodeView is
|
||||||
# messy and ill-defined.
|
# messy and ill-defined.
|
||||||
self._breakpoints = defaultdict( dict )
|
self._line_breakpoints = defaultdict( list )
|
||||||
self._configuration = None
|
self._configuration = None
|
||||||
|
|
||||||
vim.command( 'sign define vimspectorBP text==> texthl=Error' )
|
vim.command( 'sign define vimspectorBP text==> texthl=Error' )
|
||||||
|
|
@ -64,21 +64,28 @@ class DebugSession( object ):
|
||||||
if not file_name:
|
if not file_name:
|
||||||
return
|
return
|
||||||
|
|
||||||
if line in self._breakpoints[ file_name ]:
|
found_bp = False
|
||||||
bp = self._breakpoints[ file_name ][ line ]
|
for index, bp in enumerate( self._line_breakpoints[ file_name] ):
|
||||||
if bp[ 'state' ] == 'ENABLED':
|
if bp[ 'line' ] == line:
|
||||||
bp[ 'state' ] = 'DISABLED'
|
found_bp = True
|
||||||
else:
|
if bp[ 'state' ] == 'ENABLED':
|
||||||
if 'sign_id' in bp:
|
bp[ 'state' ] = 'DISABLED'
|
||||||
vim.command( 'sign unplace {0}'.format( bp[ 'sign_id' ] ) )
|
else:
|
||||||
del self._breakpoints[ file_name ][ line ]
|
if 'sign_id' in bp:
|
||||||
else:
|
vim.command( 'sign unplace {0}'.format( bp[ 'sign_id' ] ) )
|
||||||
self._breakpoints[ file_name ][ line ] = {
|
del self._line_breakpoints[ file_name ][ index ]
|
||||||
|
|
||||||
|
if not found_bp:
|
||||||
|
self._line_breakpoints[ file_name ].append( {
|
||||||
'state': 'ENABLED',
|
'state': 'ENABLED',
|
||||||
|
'line': line,
|
||||||
|
# 'sign_id': <filled in when placed>,
|
||||||
|
#
|
||||||
|
# Used by other breakpoint types:
|
||||||
# 'condition': ...,
|
# 'condition': ...,
|
||||||
# 'hitCondition': ...,
|
# 'hitCondition': ...,
|
||||||
# 'logMessage': ...
|
# 'logMessage': ...
|
||||||
}
|
} )
|
||||||
|
|
||||||
if self._connection:
|
if self._connection:
|
||||||
self._SendBreakpoints()
|
self._SendBreakpoints()
|
||||||
|
|
@ -389,6 +396,8 @@ class DebugSession( object ):
|
||||||
'command': 'configurationDone',
|
'command': 'configurationDone',
|
||||||
} )
|
} )
|
||||||
|
|
||||||
|
self._stackTraceView.LoadThreads( True )
|
||||||
|
|
||||||
def OnEvent_thread( self, message ):
|
def OnEvent_thread( self, message ):
|
||||||
if message[ 'body' ][ 'reason' ] == 'started':
|
if message[ 'body' ][ 'reason' ] == 'started':
|
||||||
pass
|
pass
|
||||||
|
|
@ -421,8 +430,8 @@ class DebugSession( object ):
|
||||||
self.Clear()
|
self.Clear()
|
||||||
|
|
||||||
def _RemoveBreakpoints( self ):
|
def _RemoveBreakpoints( self ):
|
||||||
for file_name, line_breakpoints in self._breakpoints.items():
|
for breakpoints in self._line_breakpoints.values():
|
||||||
for line, bp in line_breakpoints.items():
|
for bp in breakpoints:
|
||||||
if 'sign_id' in bp:
|
if 'sign_id' in bp:
|
||||||
vim.command( 'sign unplace {0}'.format( bp[ 'sign_id' ] ) )
|
vim.command( 'sign unplace {0}'.format( bp[ 'sign_id' ] ) )
|
||||||
del bp[ 'sign_id' ]
|
del bp[ 'sign_id' ]
|
||||||
|
|
@ -430,10 +439,9 @@ class DebugSession( object ):
|
||||||
def _SendBreakpoints( self ):
|
def _SendBreakpoints( self ):
|
||||||
self._codeView.ClearBreakpoints()
|
self._codeView.ClearBreakpoints()
|
||||||
|
|
||||||
for file_name, line_breakpoints in self._breakpoints.items():
|
for file_name, line_breakpoints in self._line_breakpoints.items():
|
||||||
breakpoints = []
|
breakpoints = []
|
||||||
lines = []
|
for bp in line_breakpoints:
|
||||||
for line, bp in line_breakpoints.items():
|
|
||||||
if bp[ 'state' ] != 'ENABLED':
|
if bp[ 'state' ] != 'ENABLED':
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
@ -441,8 +449,7 @@ class DebugSession( object ):
|
||||||
vim.command( 'sign unplace {0}'.format( bp[ 'sign_id' ] ) )
|
vim.command( 'sign unplace {0}'.format( bp[ 'sign_id' ] ) )
|
||||||
del bp[ 'sign_id' ]
|
del bp[ 'sign_id' ]
|
||||||
|
|
||||||
breakpoints.append( { 'line': line } )
|
breakpoints.append( { 'line': bp[ 'line' ] } )
|
||||||
lines.append( line )
|
|
||||||
|
|
||||||
source = {
|
source = {
|
||||||
'name': os.path.basename( file_name ),
|
'name': os.path.basename( file_name ),
|
||||||
|
|
@ -455,16 +462,15 @@ class DebugSession( object ):
|
||||||
'command': 'setBreakpoints',
|
'command': 'setBreakpoints',
|
||||||
'arguments': {
|
'arguments': {
|
||||||
'source': source,
|
'source': source,
|
||||||
'breakpoints': breakpoints
|
'breakpoints': breakpoints,
|
||||||
},
|
},
|
||||||
'lines': lines,
|
|
||||||
'sourceModified': False, # TODO: We can actually check this
|
'sourceModified': False, # TODO: We can actually check this
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
def _ShowBreakpoints( self ):
|
def _ShowBreakpoints( self ):
|
||||||
for file_name, line_breakpoints in self._breakpoints.items():
|
for file_name, line_breakpoints in self._line_breakpoints.items():
|
||||||
for line, bp in line_breakpoints.items():
|
for bp in line_breakpoints:
|
||||||
if 'sign_id' in bp:
|
if 'sign_id' in bp:
|
||||||
vim.command( 'sign unplace {0}'.format( bp[ 'sign_id' ] ) )
|
vim.command( 'sign unplace {0}'.format( bp[ 'sign_id' ] ) )
|
||||||
else:
|
else:
|
||||||
|
|
@ -474,7 +480,7 @@ class DebugSession( object ):
|
||||||
vim.command(
|
vim.command(
|
||||||
'sign place {0} line={1} name={2} file={3}'.format(
|
'sign place {0} line={1} name={2} file={3}'.format(
|
||||||
bp[ 'sign_id' ] ,
|
bp[ 'sign_id' ] ,
|
||||||
line,
|
bp[ 'line' ],
|
||||||
'vimspectorBP' if bp[ 'state' ] == 'ENABLED'
|
'vimspectorBP' if bp[ 'state' ] == 'ENABLED'
|
||||||
else 'vimspectorBPDisabled',
|
else 'vimspectorBPDisabled',
|
||||||
file_name ) )
|
file_name ) )
|
||||||
|
|
|
||||||
|
|
@ -51,15 +51,14 @@ class OutputView( object ):
|
||||||
with utils.RestorCurrentWindow():
|
with utils.RestorCurrentWindow():
|
||||||
vim.current.window = self._window
|
vim.current.window = self._window
|
||||||
|
|
||||||
vim.command( 'enew' )
|
with utils.RestoreCurrentBuffer( self._window ):
|
||||||
self._buffers[ category ] = vim.current.buffer
|
vim.command( 'enew' )
|
||||||
self._buffers[ category ].append( category + '-----' )
|
self._buffers[ category ] = vim.current.buffer
|
||||||
|
self._buffers[ category ].append( category + '-----' )
|
||||||
|
|
||||||
utils.SetUpHiddenBuffer( self._buffers[ category ],
|
utils.SetUpHiddenBuffer( self._buffers[ category ],
|
||||||
'vimspector.Output:{0}'.format( category ) )
|
'vimspector.Output:{0}'.format( category ) )
|
||||||
|
|
||||||
vim.command( "nnoremenu WinBar.{0} "
|
vim.command( "nnoremenu WinBar.{0} "
|
||||||
":call vimspector#ShowOutput( '{0}' )<CR>".format(
|
":call vimspector#ShowOutput( '{0}' )<CR>".format(
|
||||||
utils.Escape( category ) ) )
|
utils.Escape( category ) ) )
|
||||||
|
|
||||||
vim.command( 'bu #' )
|
|
||||||
|
|
|
||||||
|
|
@ -122,7 +122,8 @@ class StackTraceView( object ):
|
||||||
thread = self._line_to_thread[ current_line ]
|
thread = self._line_to_thread[ current_line ]
|
||||||
if '_frames' in thread:
|
if '_frames' in thread:
|
||||||
del thread[ '_frames' ]
|
del thread[ '_frames' ]
|
||||||
self._DrawThreads()
|
with utils.RestoreCursorPosition():
|
||||||
|
self._DrawThreads()
|
||||||
else:
|
else:
|
||||||
self._LoadStackTrace( thread, False )
|
self._LoadStackTrace( thread, False )
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -84,11 +84,13 @@ def RestorCurrentWindow():
|
||||||
|
|
||||||
@contextlib.contextmanager
|
@contextlib.contextmanager
|
||||||
def RestoreCurrentBuffer( window ):
|
def RestoreCurrentBuffer( window ):
|
||||||
old_buffer_name = window.buffer.name
|
old_buffer = window.buffer
|
||||||
try:
|
try:
|
||||||
yield
|
yield
|
||||||
finally:
|
finally:
|
||||||
window.buffer.name = old_buffer_name
|
with RestorCurrentWindow():
|
||||||
|
vim.current.window = window
|
||||||
|
vim.current.buffer = old_buffer
|
||||||
|
|
||||||
|
|
||||||
@contextlib.contextmanager
|
@contextlib.contextmanager
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue