diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index 45fb531d370..babae9eae8b 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -146,6 +146,7 @@ void ScriptTextEditor::set_edited_resource(const Ref &p_res) { ERR_FAIL_COND(p_res.is_null()); script = p_res; + script->connect_changed(callable_mp((ScriptEditorBase *)this, &ScriptEditorBase::reload_text)); code_editor->get_text_editor()->set_text(script->get_source_code()); code_editor->get_text_editor()->clear_undo_history(); diff --git a/modules/gdscript/doc_classes/@GDScript.xml b/modules/gdscript/doc_classes/@GDScript.xml index 933bfba5bad..b335bf8faec 100644 --- a/modules/gdscript/doc_classes/@GDScript.xml +++ b/modules/gdscript/doc_classes/@GDScript.xml @@ -627,7 +627,7 @@ [/codeblock] [b]Note:[/b] Only the script can have a custom icon. Inner classes are not supported. [b]Note:[/b] As annotations describe their subject, the [annotation @icon] annotation must be placed before the class definition and inheritance. - [b]Note:[/b] Unlike other annotations, the argument of the [annotation @icon] annotation must be a string literal (constant expressions are not supported). + [b]Note:[/b] Unlike most other annotations, the argument of the [annotation @icon] annotation must be a string literal (constant expressions are not supported). @@ -681,6 +681,14 @@ [b]Note:[/b] As annotations describe their subject, the [annotation @tool] annotation must be placed before the class definition and inheritance. + + + + + Stores information about UID of this script. This annotation is auto-generated when saving the script and must not be modified manually. Only applies to scripts saved as separate files (i.e. not built-in). + [b]Note:[/b] Unlike most other annotations, the argument of the [annotation @uid] annotation must be a string literal (constant expressions are not supported). + + diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp index 1f0830aa174..c4509aa5c3d 100644 --- a/modules/gdscript/gdscript.cpp +++ b/modules/gdscript/gdscript.cpp @@ -55,6 +55,7 @@ #ifdef TOOLS_ENABLED #include "editor/editor_paths.h" +#include "editor/editor_settings.h" #endif #include @@ -1076,6 +1077,36 @@ Ref GDScript::get_base() const { return base; } +String GDScript::get_raw_source_code(const String &p_path, bool *r_error) { + Ref f = FileAccess::open(p_path, FileAccess::READ); + if (f.is_null()) { + if (r_error) { + *r_error = true; + } + return String(); + } + return f->get_as_utf8_string(); +} + +Vector2i GDScript::get_uid_lines(const String &p_source) { + GDScriptParser parser; + parser.parse(p_source, "", false); + const GDScriptParser::ClassNode *c = parser.get_tree(); + if (!c) { + return Vector2i(-1, -1); + } + return c->uid_lines; +} + +String GDScript::create_uid_line(const String &p_uid_str) { +#ifdef TOOLS_ENABLED + if (EDITOR_GET("text_editor/completion/use_single_quotes")) { + return vformat(R"(@uid('%s') # %s)", p_uid_str, RTR("Generated automatically, do not modify.")); + } +#endif + return vformat(R"(@uid("%s") # %s)", p_uid_str, RTR("Generated automatically, do not modify.")); +} + bool GDScript::inherits_script(const Ref