Tidy up the buffer append logic
Vim seems to insist that a buffer has at least one line. This means that the first line set in the buffer object has to be a special case. Sigh. Create a method to wrap that up.
This commit is contained in:
parent
553ad95404
commit
df10cd84cf
4 changed files with 46 additions and 19 deletions
|
|
@ -32,7 +32,8 @@ class OutputView( object ):
|
||||||
self._CreateBuffer( category )
|
self._CreateBuffer( category )
|
||||||
|
|
||||||
with utils.ModifiableScratchBuffer( self._buffers[ category ] ):
|
with utils.ModifiableScratchBuffer( self._buffers[ category ] ):
|
||||||
self._buffers[ category ].append( event[ 'output' ].splitlines() )
|
utils.AppendToBuffer( self._buffers[ category ],
|
||||||
|
event[ 'output' ].splitlines() )
|
||||||
|
|
||||||
def Reset( self ):
|
def Reset( self ):
|
||||||
self.Clear()
|
self.Clear()
|
||||||
|
|
@ -54,7 +55,8 @@ class OutputView( object ):
|
||||||
with utils.RestoreCurrentBuffer( self._window ):
|
with utils.RestoreCurrentBuffer( self._window ):
|
||||||
vim.command( 'enew' )
|
vim.command( 'enew' )
|
||||||
self._buffers[ category ] = vim.current.buffer
|
self._buffers[ category ] = vim.current.buffer
|
||||||
self._buffers[ category ].append( category + '-----' )
|
utils.AppendToBuffer( self._buffers[ category ],
|
||||||
|
category + '-----' )
|
||||||
|
|
||||||
utils.SetUpHiddenBuffer( self._buffers[ category ],
|
utils.SetUpHiddenBuffer( self._buffers[ category ],
|
||||||
'vimspector.Output:{0}'.format( category ) )
|
'vimspector.Output:{0}'.format( category ) )
|
||||||
|
|
|
||||||
|
|
@ -93,8 +93,11 @@ class StackTraceView( object ):
|
||||||
for thread in self._threads:
|
for thread in self._threads:
|
||||||
icon = '+' if '_frames' not in thread else '-'
|
icon = '+' if '_frames' not in thread else '-'
|
||||||
|
|
||||||
self._buf.append( '{0} Thread: {1}'.format( icon, thread[ 'name' ] ) )
|
line = utils.AppendToBuffer(
|
||||||
self._line_to_thread[ len( self._buf ) ] = thread
|
self._buf,
|
||||||
|
'{0} Thread: {1}'.format( icon, thread[ 'name' ] ) )
|
||||||
|
|
||||||
|
self._line_to_thread[ line ] = thread
|
||||||
|
|
||||||
self._DrawStackTrace( thread )
|
self._DrawStackTrace( thread )
|
||||||
|
|
||||||
|
|
@ -193,9 +196,10 @@ class StackTraceView( object ):
|
||||||
else:
|
else:
|
||||||
source = { 'name': '<unknown>' }
|
source = { 'name': '<unknown>' }
|
||||||
|
|
||||||
self._buf.append(
|
line = utils.AppendToBuffer(
|
||||||
|
self._buf,
|
||||||
' {0}: {1}@{2}:{3}'.format( frame[ 'id' ],
|
' {0}: {1}@{2}:{3}'.format( frame[ 'id' ],
|
||||||
frame[ 'name' ],
|
frame[ 'name' ],
|
||||||
source[ 'name' ],
|
source[ 'name' ],
|
||||||
frame[ 'line' ] ) )
|
frame[ 'line' ] ) )
|
||||||
self._line_to_frame[ len( self._buf ) ] = frame
|
self._line_to_frame[ line ] = frame
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ _log_handler = logging.FileHandler( os.path.expanduser( '~/.vimspector.log' ) )
|
||||||
_log_handler.setFormatter(
|
_log_handler.setFormatter(
|
||||||
logging.Formatter( '%(asctime)s - %(levelname)s - %(message)s' ) )
|
logging.Formatter( '%(asctime)s - %(levelname)s - %(message)s' ) )
|
||||||
|
|
||||||
|
|
||||||
def SetUpLogging( logger ):
|
def SetUpLogging( logger ):
|
||||||
logger.setLevel( logging.DEBUG )
|
logger.setLevel( logging.DEBUG )
|
||||||
if _log_handler not in logger.handlers:
|
if _log_handler not in logger.handlers:
|
||||||
|
|
@ -171,3 +172,20 @@ def SelectFromList( prompt, options ):
|
||||||
def AskForInput( prompt ):
|
def AskForInput( prompt ):
|
||||||
with InputSave():
|
with InputSave():
|
||||||
return vim.eval( "input( '{0}' )".format( Escape( prompt ) ) )
|
return vim.eval( "input( '{0}' )".format( Escape( prompt ) ) )
|
||||||
|
|
||||||
|
|
||||||
|
def AppendToBuffer( buf, line_or_lines ):
|
||||||
|
# After clearing the buffer (using buf[:] = None) there is always a single
|
||||||
|
# empty line in the buffer object and no "is empty" method.
|
||||||
|
if len( buf ) > 1 or buf[ 0 ]:
|
||||||
|
line = len( buf ) + 1
|
||||||
|
buf.append( line_or_lines )
|
||||||
|
elif isinstance( line_or_lines, str ):
|
||||||
|
line = 1
|
||||||
|
buf[-1] = line_or_lines
|
||||||
|
else:
|
||||||
|
line = 1
|
||||||
|
buf[:] = line_or_lines
|
||||||
|
|
||||||
|
# Return the first Vim line number (1-based) that we just set.
|
||||||
|
return line
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ from vimspector import utils
|
||||||
|
|
||||||
View = namedtuple( 'View', [ 'win', 'lines', 'draw' ] )
|
View = namedtuple( 'View', [ 'win', 'lines', 'draw' ] )
|
||||||
|
|
||||||
|
|
||||||
class VariablesView( object ):
|
class VariablesView( object ):
|
||||||
def __init__( self, connection, variables_win, watches_win ):
|
def __init__( self, connection, variables_win, watches_win ):
|
||||||
self._vars = View( variables_win, {}, self._DrawScopes )
|
self._vars = View( variables_win, {}, self._DrawScopes )
|
||||||
|
|
@ -190,8 +191,8 @@ class VariablesView( object ):
|
||||||
|
|
||||||
def _DrawVariables( self, view, variables, indent ):
|
def _DrawVariables( self, view, variables, indent ):
|
||||||
for variable in variables:
|
for variable in variables:
|
||||||
view.lines[ len( view.win.buffer ) + 1 ] = variable
|
line = utils.AppendToBuffer(
|
||||||
view.win.buffer.append(
|
view.win.buffer,
|
||||||
'{indent}{icon} {name} ({type_}): {value}'.format(
|
'{indent}{icon} {name} ({type_}): {value}'.format(
|
||||||
indent = ' ' * indent,
|
indent = ' ' * indent,
|
||||||
icon = '+' if ( variable[ 'variablesReference' ] > 0 and
|
icon = '+' if ( variable[ 'variablesReference' ] > 0 and
|
||||||
|
|
@ -199,6 +200,7 @@ class VariablesView( object ):
|
||||||
name = variable[ 'name' ],
|
name = variable[ 'name' ],
|
||||||
type_ = variable.get( 'type', '<unknown type>' ),
|
type_ = variable.get( 'type', '<unknown type>' ),
|
||||||
value = variable.get( 'value', '<unknown value>' ) ).split( '\n' ) )
|
value = variable.get( 'value', '<unknown value>' ) ).split( '\n' ) )
|
||||||
|
view.lines[ line ] = variable
|
||||||
|
|
||||||
if '_variables' in variable:
|
if '_variables' in variable:
|
||||||
self._DrawVariables( view, variable[ '_variables' ], indent + 2 )
|
self._DrawVariables( view, variable[ '_variables' ], indent + 2 )
|
||||||
|
|
@ -216,22 +218,22 @@ class VariablesView( object ):
|
||||||
with utils.RestoreCursorPosition():
|
with utils.RestoreCursorPosition():
|
||||||
with utils.ModifiableScratchBuffer( self._watch.win.buffer ):
|
with utils.ModifiableScratchBuffer( self._watch.win.buffer ):
|
||||||
self._watch.win.buffer[:] = None
|
self._watch.win.buffer[:] = None
|
||||||
self._watch.win.buffer.append( 'Watches: ----' )
|
utils.AppendToBuffer( self._watch.win.buffer, 'Watches: ----' )
|
||||||
for watch in self._watches:
|
for watch in self._watches:
|
||||||
self._watch.win.buffer.append(
|
line = utils.AppendToBuffer( self._watch.win.buffer,
|
||||||
'Expression: ' + watch[ 'expression' ] )
|
'Expression: ' + watch[ 'expression' ] )
|
||||||
watch[ '_line' ] = len( self._watch.win.buffer )
|
watch[ '_line' ] = line
|
||||||
self._DrawWatchResult( 2, watch )
|
self._DrawWatchResult( 2, watch )
|
||||||
|
|
||||||
def _DrawScope( self, indent, scope ):
|
def _DrawScope( self, indent, scope ):
|
||||||
icon = '+' if ( scope[ 'variablesReference' ] > 0 and
|
icon = '+' if ( scope[ 'variablesReference' ] > 0 and
|
||||||
'_variables' not in scope ) else '-'
|
'_variables' not in scope ) else '-'
|
||||||
|
|
||||||
self._vars.lines[ len( self._vars.win.buffer ) + 1 ] = scope
|
line = utils.AppendToBuffer( self._vars.win.buffer,
|
||||||
self._vars.win.buffer.append( '{0}{1} Scope: {2}'.format(
|
'{0}{1} Scope: {2}'.format( ' ' * indent,
|
||||||
' ' * indent,
|
icon,
|
||||||
icon,
|
scope[ 'name' ] ) )
|
||||||
scope[ 'name' ] ) )
|
self._vars.lines[ line ] = scope
|
||||||
|
|
||||||
if '_variables' in scope:
|
if '_variables' in scope:
|
||||||
indent += 2
|
indent += 2
|
||||||
|
|
@ -242,7 +244,6 @@ class VariablesView( object ):
|
||||||
return
|
return
|
||||||
|
|
||||||
result = watch[ '_result' ]
|
result = watch[ '_result' ]
|
||||||
self._watch.lines[ len( self._watch.win.buffer ) + 1 ] = result
|
|
||||||
|
|
||||||
icon = '+' if ( result[ 'variablesReference' ] > 0 and
|
icon = '+' if ( result[ 'variablesReference' ] > 0 and
|
||||||
'_variables' not in result ) else '-'
|
'_variables' not in result ) else '-'
|
||||||
|
|
@ -250,7 +251,9 @@ class VariablesView( object ):
|
||||||
line = '{0}{1} Result: {2} '.format( ' ' * indent,
|
line = '{0}{1} Result: {2} '.format( ' ' * indent,
|
||||||
icon,
|
icon,
|
||||||
result[ 'result' ] )
|
result[ 'result' ] )
|
||||||
self._watch.win.buffer.append( line.split( '\n' ) )
|
line = utils.AppendToBuffer( self._watch.win.buffer,
|
||||||
|
line.split( '\n' ) )
|
||||||
|
self._watch.lines[ line ] = result
|
||||||
|
|
||||||
if '_variables' in result:
|
if '_variables' in result:
|
||||||
indent = 4
|
indent = 4
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue