Merge pull request #108473 from mihe/clickable-diagnostics

Make file part of errors/warnings clickable in Output panel
This commit is contained in:
Thaddeus Crews 2025-09-30 20:10:42 -05:00
commit 318e6c77b5
No known key found for this signature in database
GPG key ID: 8C6E5FEB5FC03CCC

View file

@ -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,8 +199,24 @@ void EditorLog::_load_state() {
}
void EditorLog::_meta_clicked(const String &p_meta) {
Ref<RegExMatch> 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<Resource> 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() {
log->clear();
@ -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);