From cde478bda6a7ca5239daf96d0fd3cb6344c064a6 Mon Sep 17 00:00:00 2001 From: rune-scape Date: Fri, 29 Dec 2023 23:06:54 -0800 Subject: [PATCH] Hot-reload only changed scripts --- core/debugger/remote_debugger.cpp | 31 +++++++++++++++---- core/debugger/remote_debugger.h | 1 + core/object/script_language.h | 1 + core/object/script_language_extension.h | 1 + editor/debugger/editor_debugger_node.cpp | 10 ++++-- editor/debugger/editor_debugger_node.h | 3 +- editor/debugger/script_editor_debugger.cpp | 8 +++-- editor/debugger/script_editor_debugger.h | 3 +- editor/plugins/script_editor_plugin.cpp | 26 ++++++++++++++-- editor/plugins/script_editor_plugin.h | 5 ++- editor/plugins/script_text_editor.cpp | 2 +- modules/gdscript/gdscript.cpp | 29 +++++++++-------- modules/gdscript/gdscript.h | 1 + .../gdscript_text_document.cpp | 2 +- modules/mono/csharp_script.cpp | 23 ++++++++++++-- modules/mono/csharp_script.h | 1 + modules/mono/editor/editor_internal_calls.cpp | 4 +-- 17 files changed, 113 insertions(+), 38 deletions(-) diff --git a/core/debugger/remote_debugger.cpp b/core/debugger/remote_debugger.cpp index a817ea871d42..cde9e05d79e1 100644 --- a/core/debugger/remote_debugger.cpp +++ b/core/debugger/remote_debugger.cpp @@ -36,6 +36,7 @@ #include "core/debugger/engine_profiler.h" #include "core/debugger/script_debugger.h" #include "core/input/input.h" +#include "core/io/resource_loader.h" #include "core/object/script_language.h" #include "core/os/os.h" @@ -515,8 +516,9 @@ void RemoteDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) { _send_stack_vars(globals, globals_vals, 2); } else if (command == "reload_scripts") { + script_paths_to_reload = data; + } else if (command == "reload_all_scripts") { reload_all_scripts = true; - } else if (command == "breakpoint") { ERR_FAIL_COND(data.size() < 3); bool set = data[2]; @@ -591,19 +593,36 @@ void RemoteDebugger::poll_events(bool p_is_idle) { } // Reload scripts during idle poll only. - if (p_is_idle && reload_all_scripts) { - for (int i = 0; i < ScriptServer::get_language_count(); i++) { - ScriptServer::get_language(i)->reload_all_scripts(); + if (p_is_idle) { + if (reload_all_scripts) { + for (int i = 0; i < ScriptServer::get_language_count(); i++) { + ScriptServer::get_language(i)->reload_all_scripts(); + } + reload_all_scripts = false; + } else if (!script_paths_to_reload.is_empty()) { + Array scripts_to_reload; + for (int i = 0; i < script_paths_to_reload.size(); ++i) { + String path = script_paths_to_reload[i]; + Error err = OK; + Ref