Very basic balloon support.

This is a huge hack, setting it manually and never resetting it. Just
displaying the value (no breakdown) etc.

I'm tempted to drop this functionality altogether as it is of limited
use when you have the locals and watch windows.
This commit is contained in:
Ben Jackson 2018-05-27 20:23:25 +01:00
commit 6aecfb969b
4 changed files with 76 additions and 27 deletions

View file

@ -186,6 +186,14 @@ class DebugSession( object ):
def DeleteWatch( self ):
self._variablesView.DeleteWatch()
def ShowBalloon( self, winnr, expression ):
if winnr == int( self._codeView._window.number ):
self._variablesView.ShowBalloon( self._currentFrame, expression )
else:
self._logger.debug( 'Winnr {0} is not the code window {1}'.format(
winnr,
self._codeView._window.number ) )
def GoToFrame( self ):
self._stackTraceView.GoToFrame()
@ -244,11 +252,11 @@ class DebugSession( object ):
self._logger.info( 'Debug Adapter Started' )
def _StopDebugAdapter( self, callback = None ):
self._codeView.Clear()
def handler( message ):
vim.eval( 'vimspector#internal#job#StopDebugSession()' )
self._connection = None
self._stackTraceView.ConnectionClosed()
self._variablesView.ConnectionClosed()
if callback:
callback()
@ -261,7 +269,6 @@ class DebugSession( object ):
def _Initialise( self ):
# TODO: name is mandatory. forcefully add it
self._connection.DoRequest( None, {
'command': 'initialize',
'arguments': {
@ -271,6 +278,8 @@ class DebugSession( object ):
'pathFormat': 'path',
},
} )
# FIXME: name is mandatory. Forcefully add it (we should really use the
# _actual_ name, but that isn't actually remembered at this point)
if 'name' not in self._configuration[ 'configuration' ]:
self._configuration[ 'configuration' ][ 'name' ] = 'test'
@ -294,27 +303,17 @@ class DebugSession( object ):
pass
def OnEvent_breakpoint( self, message ):
# Useful:
#
# /** The reason for the event.
# Values: 'changed', 'new', 'removed', etc.
# */
reason = message[ 'body' ][ 'reason' ]
bp = message[ 'body' ][ 'breakpoint' ]
if reason == 'changed':
self._codeView.UpdateBreakpoint( bp )
elif reason == 'new':
self._codeView.AddBreakpoints( None, bp )
elif reason == 'removed':
# TODO
pass
else:
utils.UserMessage(
'Unrecognised breakpoint event (undocumented): {0}'.format( reason ),
persist = True )
def OnEvent_terminated( self, message ):
utils.UserMessage( "The program was terminated because: {0}".format(
message.get( 'body', {} ).get( 'reason', "No specific reason" ) ) )
@ -326,7 +325,6 @@ class DebugSession( object ):
with utils.ModifiableScratchBuffer( self._threadsBuffer ):
self._threadsBuffer[:] = None
def _SendBreakpoints( self ):
for file_name, line_breakpoints in self._breakpoints.items():
breakpoints = []
@ -360,19 +358,6 @@ class DebugSession( object ):
}
)
# TODO: Remove this!
# self._connection.DoRequest(
# functools.partial( self._UpdateBreakpoints, None ),
# {
# 'command': 'setFunctionBreakpoints',
# 'arguments': {
# 'breakpoints': [
# { 'name': 'main' },
# ],
# },
# }
# )
self._connection.DoRequest( None, {
'command': 'configurationDone',
} )

View file

@ -34,6 +34,10 @@ class StackTraceView( object ):
with utils.ModifiableScratchBuffer( self._buf ):
self._buf[:] = None
def ConnectionClosed( self ):
self.Clear()
self._connection = None
def LoadStackTrace( self, thread_id ):
self._connection.DoRequest( self._PrintStackTrace, {
'command': 'stackTrace',

View file

@ -51,10 +51,19 @@ class VariablesView( object ):
utils.SetUpScratchBuffer( self._buf, 'vimspector.Variables' )
vim.options[ 'balloonexpr' ] = 'vimspector#internal#balloon#BalloonExpr()'
vim.options[ 'ballooneval' ] = True
vim.options[ 'balloonevalterm' ] = True
vim.options[ 'balloondelay' ] = 250
def Clear( self ):
with utils.ModifiableScratchBuffer( self._buf ):
self._buf[:] = None
def ConnectionClosed( self ):
self.Clear()
self._connection = None
def LoadScopes( self, frame ):
def scopes_consumer( message ):
self._scopes = []
@ -198,3 +207,20 @@ class VariablesView( object ):
parent[ '_variables' ].append( variable )
self._DrawScopesAndWatches()
def ShowBalloon( self, frame, expression ):
if not self._connection:
return
def handler( message ):
vim.eval( "balloon_show( '{0}' )".format(
message[ 'body' ][ 'result' ] ) )
self._connection.DoRequest( handler, {
'command': 'evaluate',
'arguments': {
'expression': expression,
'frameId': frame[ 'id' ],
'context': 'hover',
}
} )