From 7f5933c0f34627f9c83b48ba2e5cf602f86ce357 Mon Sep 17 00:00:00 2001 From: Mikael Hermansson Date: Wed, 9 Jul 2025 14:26:58 +0200 Subject: [PATCH] Make file part of errors/warnings clickable in Output panel --- editor/editor_log.cpp | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/editor/editor_log.cpp b/editor/editor_log.cpp index 2e1fc428e56..cd0157659da 100644 --- a/editor/editor_log.cpp +++ b/editor/editor_log.cpp @@ -33,11 +33,14 @@ #include "core/object/undo_redo.h" #include "core/os/keyboard.h" #include "core/version.h" +#include "editor/docks/inspector_dock.h" #include "editor/editor_node.h" #include "editor/editor_string_names.h" #include "editor/file_system/editor_paths.h" +#include "editor/script/script_editor_plugin.h" #include "editor/settings/editor_settings.h" #include "editor/themes/editor_scale.h" +#include "modules/regex/regex.h" #include "scene/gui/separator.h" #include "scene/resources/font.h" @@ -46,9 +49,9 @@ void EditorLog::_error_handler(void *p_self, const char *p_func, const char *p_f String err_str; if (p_errorexp && p_errorexp[0]) { - err_str = String::utf8(p_errorexp); + err_str = String::utf8(p_errorexp).replace("[", "[lb]"); } else { - err_str = String::utf8(p_file) + ":" + itos(p_line) + " - " + String::utf8(p_error); + err_str = vformat("[url]%s:%d[/url] - %s", String::utf8(p_file).replace("[", "[lb]"), p_line, String::utf8(p_error).replace("[", "[lb]")); } MessageType message_type = p_type == ERR_HANDLER_WARNING ? MSG_TYPE_WARNING : MSG_TYPE_ERROR; @@ -196,7 +199,23 @@ void EditorLog::_load_state() { } void EditorLog::_meta_clicked(const String &p_meta) { - OS::get_singleton()->shell_open(p_meta); + Ref uri_match = RegEx(R"(^([a-zA-Z][a-zA-Z0-9+.-]*):(?://)?(.+?)(?::([0-9]+))?$)").search(p_meta); + if (uri_match.is_null()) { + return; + } + + String scheme = uri_match->get_string(1); + if (scheme == "res") { + String file = uri_match->get_string(2); + int line = (int)uri_match->get_string(3).to_int(); + if (ResourceLoader::exists(file)) { + Ref res = ResourceLoader::load(file); + ScriptEditor::get_singleton()->edit(res, line - 1, 0); + InspectorDock::get_singleton()->edit_resource(res); + } + } else { + OS::get_singleton()->shell_open(p_meta); + } } void EditorLog::_clear_request() { @@ -384,7 +403,8 @@ void EditorLog::_add_log_line(LogMessage &p_message, bool p_replace_previous) { log->pop(); } - if (p_message.type == MSG_TYPE_STD_RICH) { + // Note that errors and warnings only support BBCode in the file part of the message. + if (p_message.type == MSG_TYPE_STD_RICH || p_message.type == MSG_TYPE_ERROR || p_message.type == MSG_TYPE_WARNING) { log->append_text(p_message.text); } else { log->add_text(p_message.text);