1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-05 12:10:55 +00:00

Support REPL expressions through DAP evaluate request

This commit is contained in:
Ricardo Subtil
2024-09-30 14:15:09 +01:00
parent 6aac039ee7
commit 0d098d3cca
6 changed files with 71 additions and 11 deletions

View File

@@ -30,6 +30,8 @@
#include "debug_adapter_parser.h"
#include "core/variant/variant.h"
#include "editor/debugger/debug_adapter/debug_adapter_types.h"
#include "editor/debugger/editor_debugger_node.h"
#include "editor/debugger/script_editor_debugger.h"
#include "editor/export/editor_export_platform.h"
@@ -487,16 +489,27 @@ Dictionary DebugAdapterParser::req_stepIn(const Dictionary &p_params) const {
}
Dictionary DebugAdapterParser::req_evaluate(const Dictionary &p_params) const {
Dictionary response = prepare_success_response(p_params), body;
response["body"] = body;
Dictionary args = p_params["arguments"];
String expression = args["expression"];
int frame_id = args.has("frameId") ? static_cast<int>(args["frameId"]) : DebugAdapterProtocol::get_singleton()->_current_frame;
String value = EditorDebuggerNode::get_singleton()->get_var_value(args["expression"]);
body["result"] = value;
body["variablesReference"] = 0;
if (HashMap<String, DAP::Variable>::Iterator E = DebugAdapterProtocol::get_singleton()->eval_list.find(expression); E) {
Dictionary response = prepare_success_response(p_params);
Dictionary body;
response["body"] = body;
return response;
DAP::Variable var = E->value;
body["result"] = var.value;
body["variablesReference"] = var.variablesReference;
// Since an evaluation can alter the state of the debuggee, they are volatile, and should only be used once
DebugAdapterProtocol::get_singleton()->eval_list.erase(E->key);
return response;
} else {
DebugAdapterProtocol::get_singleton()->request_remote_evaluate(expression, frame_id);
}
return Dictionary();
}
Dictionary DebugAdapterParser::req_godot_put_msg(const Dictionary &p_params) const {