Skip to content

Commit

Permalink
Implemented richInspectVariable request handler
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanMabille committed Jul 22, 2021
1 parent 4be87de commit 1ebe508
Showing 1 changed file with 56 additions and 1 deletion.
57 changes: 56 additions & 1 deletion ipykernel/debugger.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class Debugger:

# Requests that can be handled even if the debugger is not running
static_debug_msg_types = [
'debugInfo', 'inspectVariables'
'debugInfo', 'inspectVariables', 'richInspectVariables'
]

def __init__(self, log, debugpy_stream, event_callback, shell_socket, session):
Expand Down Expand Up @@ -445,6 +445,61 @@ async def inspectVariables(self, message):
}
return reply

async def richInspectVariables(self, message):
print('COINCOIN')
var_name = message['arguments']['variableName']
var_repr_data = var_name + '_repr_data'
var_repr_metadata = var_name + '_repr_metadata'

if not self.breakpoint_list:
# The code did not hit a breakpoint, we use the intepreter
# to get the rich representation of the variable
var_repr_data, var_repr_metadata = get_ipython().display_formatter.format(var_name)
else:
# The code has stopped on a breakpoint, we use the setExpression
# request to get the rich representation of the variable
lvalue = var_repr_data + ',' + var_repr_metadata
code = 'get_ipython().display_formatter.format(' + var_name+')'
frame_id = message['arguments']['frameId']
seq = message['seq']
request = {
'type': 'request',
'command': 'setExpression',
'seq': seq+1,
'arguments': {
'expression': lvalue,
'value': code,
'frameId': frameId
}
}
await self._forward_message(request)

reply = {
'type': 'response',
'sequence_seq': message['seq'],
'success': False,
'command': message['command']
}

repr_data = globals()[var_repr_data]
repr_metadata = globals()[var_repr_metadata]
body = {
'data': {},
'metadata': {}
}

for key, value in repr_data.items():
body['data']['key'] = value
if repr_metadata.has_key(key):
body['metadata'][key] = repr_metadata[key]

globals().pop(var_repr_data)
globals().pop(var_repr_metadata)

reply['body'] = body
reply['success'] = True
return reply

async def process_request(self, message):
reply = {}

Expand Down

0 comments on commit 1ebe508

Please sign in to comment.