From 175870ccc786f6071772972a08b6d8dda9a6d4c8 Mon Sep 17 00:00:00 2001 From: kobewi Date: Thu, 11 Nov 2021 19:50:27 +0100 Subject: [PATCH] Show built-in script names in the debugger (cherry picked from commit 3b320cd9feb0ce89020f898f0ae5ecc07a25ce51) --- modules/gdscript/gdscript.cpp | 14 +++++++++++--- modules/gdscript/gdscript.h | 1 + 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp index 3a7e668dfdd..7dc3369bcb6 100644 --- a/modules/gdscript/gdscript.cpp +++ b/modules/gdscript/gdscript.cpp @@ -296,7 +296,7 @@ ScriptInstance *GDScript::instance_create(Object *p_this) { if (top->native.is_valid()) { if (!ClassDB::is_parent_class(p_this->get_class_name(), top->native->get_name())) { if (ScriptDebugger::get_singleton()) { - GDScriptLanguage::get_singleton()->debug_break_parse(get_path(), 1, "Script inherits from native type '" + String(top->native->get_name()) + "', so it can't be instanced in object of type: '" + p_this->get_class() + "'"); + GDScriptLanguage::get_singleton()->debug_break_parse(_get_debug_path(), 1, "Script inherits from native type '" + String(top->native->get_name()) + "', so it can't be instanced in object of type: '" + p_this->get_class() + "'"); } ERR_FAIL_V_MSG(nullptr, "Script inherits from native type '" + String(top->native->get_name()) + "', so it can't be instanced in object of type '" + p_this->get_class() + "'" + "."); } @@ -533,6 +533,14 @@ void GDScript::_set_subclass_path(Ref &p_sc, const String &p_path) { } } +String GDScript::_get_debug_path() const { + if ((get_path().empty() || get_path().find("::") != -1) && !get_name().empty()) { + return get_name() + " (" + get_path().get_slice("::", 0) + ")"; + } else { + return get_path(); + } +} + Error GDScript::reload(bool p_keep_state) { GDScriptLanguage::singleton->lock.lock(); bool has_instances = instances.size(); @@ -560,7 +568,7 @@ Error GDScript::reload(bool p_keep_state) { Error err = parser.parse(source, basedir, false, path); if (err) { if (ScriptDebugger::get_singleton()) { - GDScriptLanguage::get_singleton()->debug_break_parse(get_path(), parser.get_error_line(), "Parser Error: " + parser.get_error()); + GDScriptLanguage::get_singleton()->debug_break_parse(_get_debug_path(), parser.get_error_line(), "Parser Error: " + parser.get_error()); } _err_print_error("GDScript::reload", path.empty() ? "built-in" : (const char *)path.utf8().get_data(), parser.get_error_line(), ("Parse Error: " + parser.get_error()).utf8().get_data(), ERR_HANDLER_SCRIPT); ERR_FAIL_V(ERR_PARSE_ERROR); @@ -574,7 +582,7 @@ Error GDScript::reload(bool p_keep_state) { if (err) { if (can_run) { if (ScriptDebugger::get_singleton()) { - GDScriptLanguage::get_singleton()->debug_break_parse(get_path(), compiler.get_error_line(), "Parser Error: " + compiler.get_error()); + GDScriptLanguage::get_singleton()->debug_break_parse(_get_debug_path(), compiler.get_error_line(), "Parser Error: " + compiler.get_error()); } _err_print_error("GDScript::reload", path.empty() ? "built-in" : (const char *)path.utf8().get_data(), compiler.get_error_line(), ("Compile Error: " + compiler.get_error()).utf8().get_data(), ERR_HANDLER_SCRIPT); ERR_FAIL_V(ERR_COMPILATION_FAILED); diff --git a/modules/gdscript/gdscript.h b/modules/gdscript/gdscript.h index 026e0c3455e..9efb542d840 100644 --- a/modules/gdscript/gdscript.h +++ b/modules/gdscript/gdscript.h @@ -116,6 +116,7 @@ class GDScript : public Script { GDScriptInstance *_create_instance(const Variant **p_args, int p_argcount, Object *p_owner, bool p_isref, Variant::CallError &r_error); void _set_subclass_path(Ref &p_sc, const String &p_path); + String _get_debug_path() const; #ifdef TOOLS_ENABLED Set placeholders;