Support display of variables (sort of)
This displays the entire hierarchy in a window. This is about as inefficient as could possibly be, but for trivial things allows you to see the variables at least.
This commit is contained in:
parent
bd3a74970e
commit
b15c4a0902
1 changed files with 70 additions and 1 deletions
|
|
@ -18,6 +18,7 @@ import vim
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import contextlib
|
import contextlib
|
||||||
|
from functools import partial
|
||||||
|
|
||||||
_logger = logging.getLogger( __name__ )
|
_logger = logging.getLogger( __name__ )
|
||||||
|
|
||||||
|
|
@ -51,7 +52,6 @@ def ModifiableScratchBuffer( buf ):
|
||||||
buf.options[ 'readonly' ] = True
|
buf.options[ 'readonly' ] = True
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class DebugSession( object ):
|
class DebugSession( object ):
|
||||||
def __init__( self, channel_send_func ):
|
def __init__( self, channel_send_func ):
|
||||||
SetUpLogging()
|
SetUpLogging()
|
||||||
|
|
@ -65,14 +65,17 @@ class DebugSession( object ):
|
||||||
self._codeWindow = None
|
self._codeWindow = None
|
||||||
self._callStackBuffer = None
|
self._callStackBuffer = None
|
||||||
self._threadsBuffer = None
|
self._threadsBuffer = None
|
||||||
|
self._localsBuffer = None
|
||||||
self._outputBuffer = None
|
self._outputBuffer = None
|
||||||
|
|
||||||
# TODO: How to hold/model this data
|
# TODO: How to hold/model this data
|
||||||
self._currentThread = None
|
self._currentThread = None
|
||||||
self._currentFrame = None
|
self._currentFrame = None
|
||||||
|
self._scopes = []
|
||||||
|
|
||||||
self._SetUpUI()
|
self._SetUpUI()
|
||||||
|
|
||||||
|
|
||||||
def _SetUpUI( self ):
|
def _SetUpUI( self ):
|
||||||
vim.command( 'tabnew' )
|
vim.command( 'tabnew' )
|
||||||
self._uiTab = vim.current.tabpage
|
self._uiTab = vim.current.tabpage
|
||||||
|
|
@ -93,10 +96,14 @@ class DebugSession( object ):
|
||||||
vim.command( 'spl' )
|
vim.command( 'spl' )
|
||||||
vim.command( 'enew' )
|
vim.command( 'enew' )
|
||||||
self._outputBuffer = vim.current.buffer
|
self._outputBuffer = vim.current.buffer
|
||||||
|
vim.command( 'spl' )
|
||||||
|
vim.command( 'enew' )
|
||||||
|
self._localsBuffer = vim.current.buffer
|
||||||
|
|
||||||
SetUpScratchBuffer( self._threadsBuffer )
|
SetUpScratchBuffer( self._threadsBuffer )
|
||||||
SetUpScratchBuffer( self._callStackBuffer )
|
SetUpScratchBuffer( self._callStackBuffer )
|
||||||
SetUpScratchBuffer( self._outputBuffer )
|
SetUpScratchBuffer( self._outputBuffer )
|
||||||
|
SetUpScratchBuffer( self._localsBuffer )
|
||||||
|
|
||||||
def _LoadFrame( self, frame ):
|
def _LoadFrame( self, frame ):
|
||||||
vim.current.window = self._codeWindow
|
vim.current.window = self._codeWindow
|
||||||
|
|
@ -110,6 +117,68 @@ class DebugSession( object ):
|
||||||
raise
|
raise
|
||||||
|
|
||||||
self._codeWindow.cursor = ( frame[ 'line' ], frame[ 'column' ] )
|
self._codeWindow.cursor = ( frame[ 'line' ], frame[ 'column' ] )
|
||||||
|
self._LoadScopes( frame )
|
||||||
|
|
||||||
|
|
||||||
|
def _LoadScopes( self, frame ):
|
||||||
|
def draw_variables( variables, indent ):
|
||||||
|
for variable in variables:
|
||||||
|
self._localsBuffer.append( '{indent}{name} ({type_}): {value}'.format(
|
||||||
|
indent = ' ' * indent,
|
||||||
|
name = variable[ 'name' ],
|
||||||
|
type_ = variable.get( 'type', '<unknown type>' ),
|
||||||
|
value = variable[ 'value' ] ) )
|
||||||
|
|
||||||
|
if '_variables' in variable:
|
||||||
|
draw_variables( variable[ '_variables' ], indent + 2 )
|
||||||
|
|
||||||
|
def draw_scopes():
|
||||||
|
with ModifiableScratchBuffer( self._localsBuffer ):
|
||||||
|
self._localsBuffer[:] = None
|
||||||
|
for scope in self._scopes:
|
||||||
|
self._localsBuffer.append( scope[ 'name' ] )
|
||||||
|
if '_variables' in scope:
|
||||||
|
indent = 2
|
||||||
|
draw_variables( scope[ '_variables' ], indent )
|
||||||
|
|
||||||
|
def variables_consumer( parent, message ):
|
||||||
|
_logger.debug( 'consuming variables with parent {0}'.format( parent ) )
|
||||||
|
for variable in message[ 'body' ][ 'variables' ]:
|
||||||
|
if '_variables' not in parent:
|
||||||
|
parent[ '_variables' ] = []
|
||||||
|
|
||||||
|
parent[ '_variables' ].append( variable )
|
||||||
|
if variable[ 'variablesReference' ] > 0:
|
||||||
|
self._DoRequest( partial( variables_consumer, variable ), {
|
||||||
|
'command': 'variables',
|
||||||
|
'arguments': {
|
||||||
|
'variablesReference': variable[ 'variablesReference' ]
|
||||||
|
},
|
||||||
|
} )
|
||||||
|
|
||||||
|
draw_scopes()
|
||||||
|
|
||||||
|
def scopes_consumer( message ):
|
||||||
|
self._scopes = []
|
||||||
|
for scope in message[ 'body' ][ 'scopes' ]:
|
||||||
|
self._scopes.append( scope )
|
||||||
|
self._DoRequest( partial( variables_consumer, scope ), {
|
||||||
|
'command': 'variables',
|
||||||
|
'arguments': {
|
||||||
|
'variablesReference': scope[ 'variablesReference' ]
|
||||||
|
},
|
||||||
|
} )
|
||||||
|
|
||||||
|
draw_scopes()
|
||||||
|
|
||||||
|
|
||||||
|
self._DoRequest( scopes_consumer, {
|
||||||
|
'command': 'scopes',
|
||||||
|
'arguments': {
|
||||||
|
'frameId': frame[ 'id' ]
|
||||||
|
},
|
||||||
|
} )
|
||||||
|
|
||||||
|
|
||||||
def OnChannelData( self, data ):
|
def OnChannelData( self, data ):
|
||||||
self._connection.OnData( data )
|
self._connection.OnData( data )
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue