Format remote printerr properly in script debugger output

Fixes #33324
This commit is contained in:
PouleyKetchoupp 2019-11-29 15:06:42 +01:00
parent 44a516986d
commit 83e376e731
3 changed files with 48 additions and 6 deletions

View File

@ -33,6 +33,7 @@
#include "core/io/marshalls.h"
#include "core/project_settings.h"
#include "core/ustring.h"
#include "editor/editor_log.h"
#include "editor/plugins/canvas_item_editor_plugin.h"
#include "editor/plugins/spatial_editor_plugin.h"
#include "editor_log.h"
@ -43,6 +44,7 @@
#include "editor_settings.h"
#include "main/performance.h"
#include "property_editor.h"
#include "scene/debugger/script_debugger_remote.h"
#include "scene/gui/dialogs.h"
#include "scene/gui/label.h"
#include "scene/gui/line_edit.h"
@ -822,8 +824,26 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da
//OUT
for (int i = 0; i < p_data.size(); i++) {
Array output = p_data[i];
ERR_FAIL_COND_MSG(output.size() < 2, "Malformed output message from script debugger.");
String str = output[0];
ScriptDebuggerRemote::MessageType type = (ScriptDebuggerRemote::MessageType)(int)(output[1]);
EditorLog::MessageType msg_type;
switch (type) {
case ScriptDebuggerRemote::MESSAGE_TYPE_LOG: {
msg_type = EditorLog::MSG_TYPE_STD;
} break;
case ScriptDebuggerRemote::MESSAGE_TYPE_ERROR: {
msg_type = EditorLog::MSG_TYPE_ERROR;
} break;
default: {
WARN_PRINTS("Unhandled script debugger message type: " + itos(type));
msg_type = EditorLog::MSG_TYPE_STD;
} break;
}
String t = p_data[i];
//LOG
if (!EditorNode::get_log()->is_visible()) {
@ -833,7 +853,8 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da
}
}
}
EditorNode::get_log()->add_message(t);
EditorNode::get_log()->add_message(str, msg_type);
}
} else if (p_msg == "performance") {

View File

@ -382,8 +382,14 @@ void ScriptDebuggerRemote::_get_output() {
packet_peer_stream->put_var(output_strings.size());
while (output_strings.size()) {
const OutputString &output_string = output_strings.front()->get();
Array msg_data;
msg_data.push_back(output_string.message);
msg_data.push_back(output_string.type);
packet_peer_stream->put_var(msg_data);
packet_peer_stream->put_var(output_strings.front()->get());
output_strings.pop_front();
}
locking = false;
@ -1157,10 +1163,15 @@ void ScriptDebuggerRemote::_print_handler(void *p_this, const String &p_string,
if (overflowed)
s += "[...]";
sdr->output_strings.push_back(s);
OutputString output_string;
output_string.message = s;
output_string.type = p_error ? MESSAGE_TYPE_ERROR : MESSAGE_TYPE_LOG;
sdr->output_strings.push_back(output_string);
if (overflowed) {
sdr->output_strings.push_back("[output overflow, print less text!]");
output_string.message = "[output overflow, print less text!]";
output_string.type = MESSAGE_TYPE_ERROR;
sdr->output_strings.push_back(output_string);
}
}
sdr->mutex->unlock();

View File

@ -92,7 +92,12 @@ class ScriptDebuggerRemote : public ScriptDebugger {
Array callstack;
};
List<String> output_strings;
struct OutputString {
String message;
int type;
};
List<OutputString> output_strings;
List<Message> messages;
int max_messages_per_frame;
int n_messages_dropped;
@ -151,6 +156,11 @@ class ScriptDebuggerRemote : public ScriptDebugger {
bool skip_breakpoints;
public:
enum MessageType {
MESSAGE_TYPE_LOG,
MESSAGE_TYPE_ERROR,
};
struct ResourceUsage {
String path;