Marginally improve the hover text
Don't use the default padded display. When the request fails, say why. Include the type if known.
This commit is contained in:
parent
df10cd84cf
commit
88ac7f6d55
3 changed files with 37 additions and 15 deletions
|
|
@ -16,8 +16,13 @@
|
|||
import logging
|
||||
import json
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
from vimspector import utils
|
||||
|
||||
PendingRequest = namedtuple( 'PendingRequest',
|
||||
[ 'msg', 'handler', 'failure_handler' ] )
|
||||
|
||||
|
||||
class DebugAdapterConnection( object ):
|
||||
def __init__( self, handler, send_func ):
|
||||
|
|
@ -29,16 +34,18 @@ class DebugAdapterConnection( object ):
|
|||
self._buffer = bytes()
|
||||
self._handler = handler
|
||||
self._next_message_id = 0
|
||||
self._outstanding_requests = dict()
|
||||
self._outstanding_requests = {}
|
||||
|
||||
def DoRequest( self, handler, msg ):
|
||||
def DoRequest( self, handler, msg, failure_handler=None ):
|
||||
this_id = self._next_message_id
|
||||
self._next_message_id += 1
|
||||
|
||||
msg[ 'seq' ] = this_id
|
||||
msg[ 'type' ] = 'request'
|
||||
|
||||
self._outstanding_requests[ this_id ] = handler
|
||||
self._outstanding_requests[ this_id ] = PendingRequest( msg,
|
||||
handler,
|
||||
failure_handler )
|
||||
self._SendMessage( msg )
|
||||
|
||||
def Reset( self ):
|
||||
|
|
@ -132,11 +139,11 @@ class DebugAdapterConnection( object ):
|
|||
return
|
||||
|
||||
if message[ 'type' ] == 'response':
|
||||
handler = self._outstanding_requests.pop( message[ 'request_seq' ] )
|
||||
request = self._outstanding_requests.pop( message[ 'request_seq' ] )
|
||||
|
||||
if message[ 'success' ]:
|
||||
if handler:
|
||||
handler( message )
|
||||
if request.handler:
|
||||
request.handler( message )
|
||||
else:
|
||||
reason = message.get( 'message' )
|
||||
if not message:
|
||||
|
|
@ -148,9 +155,10 @@ class DebugAdapterConnection( object ):
|
|||
message = 'No reason'
|
||||
|
||||
self._logger.error( 'Request failed: {0}'.format( reason ) )
|
||||
utils.UserMessage( 'Request failed: {0}'.format( reason ) )
|
||||
|
||||
|
||||
if request.failure_handler:
|
||||
request.failure_handler( reason, message )
|
||||
else:
|
||||
utils.UserMessage( 'Request failed: {0}'.format( reason ) )
|
||||
elif message[ 'type' ] == 'event':
|
||||
method = 'OnEvent_' + message[ 'event' ]
|
||||
if method in dir( self._handler ):
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
# limitations under the License.
|
||||
|
||||
import vim
|
||||
import json
|
||||
from collections import namedtuple
|
||||
from functools import partial
|
||||
|
||||
|
|
@ -92,8 +93,6 @@ class VariablesView( object ):
|
|||
for k, v in self._oldoptions.items():
|
||||
vim.options[ k ] = v
|
||||
|
||||
# TODO: delete the buffer?
|
||||
|
||||
def LoadScopes( self, frame ):
|
||||
def scopes_consumer( message ):
|
||||
self._scopes = []
|
||||
|
|
@ -273,8 +272,23 @@ class VariablesView( object ):
|
|||
return
|
||||
|
||||
def handler( message ):
|
||||
vim.eval( "balloon_show( '{0}' )".format(
|
||||
utils.Escape( message[ 'body' ][ 'result' ] ) ) )
|
||||
# TODO: this result count be expandable, but we have no way to allow the
|
||||
# user to interact with the balloon to expand it.
|
||||
body = message[ 'body' ]
|
||||
ref = body.get( 'variablesReference', 0 )
|
||||
icon = '+ ' if ref > 0 else ''
|
||||
display = [
|
||||
'Type: ' + body.get( 'type', '<unknown>' ),
|
||||
icon + 'Value: ' + body[ 'result' ]
|
||||
]
|
||||
vim.eval( "balloon_show( {0} )".format(
|
||||
json.dumps( display ) ) )
|
||||
|
||||
def failure_handler( reason, message ):
|
||||
display = [ reason ]
|
||||
vim.eval( "balloon_show( {0} )".format(
|
||||
json.dumps( display ) ) )
|
||||
|
||||
|
||||
self._connection.DoRequest( handler, {
|
||||
'command': 'evaluate',
|
||||
|
|
@ -283,4 +297,4 @@ class VariablesView( object ):
|
|||
'frameId': frame[ 'id' ],
|
||||
'context': 'hover',
|
||||
}
|
||||
} )
|
||||
}, failure_handler )
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue