Skip to content

Commit 7b213c6

Browse files
committed
Add option to filter errors from script side via EditorDebuggerPlugin
1 parent c83e891 commit 7b213c6

6 files changed

+46
-0
lines changed

doc/classes/EditorDebuggerPlugin.xml

+7
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@
7171
Override this method to process incoming messages. The [param session_id] is the ID of the [EditorDebuggerSession] that received the message (which you can retrieve via [method get_session]).
7272
</description>
7373
</method>
74+
<method name="_filter_error" qualifiers="virtual const">
75+
<return type="bool" />
76+
<param index="0" name="error" type="Array" />
77+
<param index="1" name="session_id" type="int" />
78+
<description>
79+
</description>
80+
</method>
7481
<method name="_goto_script_line" qualifiers="virtual">
7582
<return type="void" />
7683
<param index="0" name="script" type="Script" />

editor/debugger/editor_debugger_node.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -837,3 +837,16 @@ bool EditorDebuggerNode::plugins_capture(ScriptEditorDebugger *p_debugger, const
837837
}
838838
return parsed;
839839
}
840+
841+
bool EditorDebuggerNode::plugins_filter_error(ScriptEditorDebugger *p_debugger, DebuggerMarshalls::OutputError &oe) {
842+
int p_session_id = tabs->get_tab_idx_from_control(p_debugger);
843+
ERR_FAIL_COND_V(p_session_id < 0, false);
844+
845+
bool filtered = false;
846+
for (Ref<EditorDebuggerPlugin> plugin : debugger_plugins) {
847+
if (plugin->filter_error(oe, p_session_id)) {
848+
filtered = true;
849+
}
850+
}
851+
return filtered;
852+
}

editor/debugger/editor_debugger_node.h

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#ifndef EDITOR_DEBUGGER_NODE_H
3232
#define EDITOR_DEBUGGER_NODE_H
3333

34+
#include "core/debugger/debugger_marshalls.h"
3435
#include "core/object/script_language.h"
3536
#include "editor/debugger/editor_debugger_server.h"
3637
#include "scene/gui/margin_container.h"
@@ -217,6 +218,7 @@ class EditorDebuggerNode : public MarginContainer {
217218
void stop(bool p_force = false);
218219

219220
bool plugins_capture(ScriptEditorDebugger *p_debugger, const String &p_message, const Array &p_data);
221+
bool plugins_filter_error(ScriptEditorDebugger *p_debugger, DebuggerMarshalls::OutputError &oe);
220222
void add_debugger_plugin(const Ref<EditorDebuggerPlugin> &p_plugin);
221223
void remove_debugger_plugin(const Ref<EditorDebuggerPlugin> &p_plugin);
222224
};

editor/debugger/script_editor_debugger.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,12 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, uint64_t p_thread
536536
bool e;
537537
String time = String("%d:%02d:%02d:%04d").sprintf(time_vals, &e);
538538

539+
540+
bool filtered = EditorDebuggerNode::get_singleton()->plugins_filter_error(this, oe);
541+
if (filtered) {
542+
goto end;
543+
}
544+
539545
// Rest of the error data.
540546
bool source_is_project_file = oe.source_file.begins_with("res://");
541547

@@ -820,6 +826,8 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, uint64_t p_thread
820826
WARN_PRINT("unknown message " + p_msg);
821827
}
822828
}
829+
830+
end:;
823831
}
824832

825833
void ScriptEditorDebugger::_set_reason_text(const String &p_reason, MessageType p_type) {

editor/plugins/editor_debugger_plugin.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
#include "editor_debugger_plugin.h"
3232

33+
#include "core/debugger/debugger_marshalls.h"
3334
#include "editor/debugger/script_editor_debugger.h"
3435

3536
void EditorDebuggerSession::_breaked(bool p_really_did, bool p_can_debug, const String &p_message, bool p_has_stackdump) {
@@ -190,6 +191,17 @@ bool EditorDebuggerPlugin::capture(const String &p_message, const Array &p_data,
190191
return false;
191192
}
192193

194+
bool EditorDebuggerPlugin::filter_error(DebuggerMarshalls::OutputError &oe, int p_session_id) {
195+
Array output_error_serialized = oe.serialize();
196+
197+
bool ret = false;
198+
if (GDVIRTUAL_CALL(_filter_error, output_error_serialized, p_session_id, ret)) {
199+
return ret;
200+
}
201+
202+
return false;
203+
}
204+
193205
void EditorDebuggerPlugin::goto_script_line(const Ref<Script> &p_script, int p_line) {
194206
GDVIRTUAL_CALL(_goto_script_line, p_script, p_line);
195207
}
@@ -206,6 +218,7 @@ void EditorDebuggerPlugin::_bind_methods() {
206218
GDVIRTUAL_BIND(_setup_session, "session_id");
207219
GDVIRTUAL_BIND(_has_capture, "capture");
208220
GDVIRTUAL_BIND(_capture, "message", "data", "session_id");
221+
GDVIRTUAL_BIND(_filter_error, "error", "session_id");
209222
GDVIRTUAL_BIND(_goto_script_line, "script", "line");
210223
GDVIRTUAL_BIND(_breakpoints_cleared_in_tree);
211224
GDVIRTUAL_BIND(_breakpoint_set_in_tree, "script", "line", "enabled");

editor/plugins/editor_debugger_plugin.h

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#ifndef EDITOR_DEBUGGER_PLUGIN_H
3232
#define EDITOR_DEBUGGER_PLUGIN_H
3333

34+
#include "core/debugger/debugger_marshalls.h"
3435
#include "scene/gui/control.h"
3536

3637
class ScriptEditorDebugger;
@@ -83,13 +84,15 @@ class EditorDebuggerPlugin : public RefCounted {
8384

8485
virtual void setup_session(int p_idx);
8586
virtual bool capture(const String &p_message, const Array &p_data, int p_session);
87+
virtual bool filter_error(DebuggerMarshalls::OutputError &oe, int p_session_id);
8688
virtual bool has_capture(const String &p_capture) const;
8789

8890
Ref<EditorDebuggerSession> get_session(int p_session_id);
8991
Array get_sessions();
9092

9193
GDVIRTUAL3R(bool, _capture, const String &, const Array &, int);
9294
GDVIRTUAL1RC(bool, _has_capture, const String &);
95+
GDVIRTUAL2RC(bool, _filter_error, const Array &, int);
9396
GDVIRTUAL1(_setup_session, int);
9497

9598
virtual void goto_script_line(const Ref<Script> &p_script, int p_line);

0 commit comments

Comments
 (0)