summaryrefslogtreecommitdiffstats
path: root/editor/editor_file_system.cpp
diff options
context:
space:
mode:
authorHilderin <81109165+Hilderin@users.noreply.github.com>2024-09-18 19:37:12 -0400
committerHilderin <81109165+Hilderin@users.noreply.github.com>2024-09-20 12:12:24 -0400
commit96382204736cbc131fbc2640ba6ba238c53017c0 (patch)
tree5f9772f97c50b8f6f8ac4a7a4b3650d6a38379d5 /editor/editor_file_system.cpp
parent694d3c2930bdfb43fd93e1e6641f66c4f19a5c77 (diff)
downloadredot-engine-96382204736cbc131fbc2640ba6ba238c53017c0.tar.gz
Fix reloading scripts already in use
Diffstat (limited to 'editor/editor_file_system.cpp')
-rw-r--r--editor/editor_file_system.cpp33
1 files changed, 25 insertions, 8 deletions
diff --git a/editor/editor_file_system.cpp b/editor/editor_file_system.cpp
index cad615e6c5..bee7fdf7b2 100644
--- a/editor/editor_file_system.cpp
+++ b/editor/editor_file_system.cpp
@@ -1973,18 +1973,16 @@ void EditorFileSystem::_update_script_documentation() {
for (int i = 0; i < ScriptServer::get_language_count(); i++) {
ScriptLanguage *lang = ScriptServer::get_language(i);
if (lang->supports_documentation() && efd->files[index]->type == lang->get_type()) {
- // Reloading the script from disk if resource already in memory. Otherwise, the
- // ResourceLoader::load will return the last loaded version of the script (without the modifications).
- // The only have the script already loaded here is to edit the script outside the
- // editor without being connected to the LSP server.
- Ref<Resource> res = ResourceCache::get_ref(path);
- if (res.is_valid()) {
- res->reload_from_file();
- }
+ bool should_reload_script = _should_reload_script(path);
Ref<Script> scr = ResourceLoader::load(path);
if (scr.is_null()) {
continue;
}
+ if (should_reload_script) {
+ // Reloading the script from disk. Otherwise, the ResourceLoader::load will
+ // return the last loaded version of the script (without the modifications).
+ scr->reload_from_file();
+ }
Vector<DocData::ClassDoc> docs = scr->get_documentation();
for (int j = 0; j < docs.size(); j++) {
EditorHelp::get_doc_data()->add_doc(docs[j]);
@@ -2006,6 +2004,25 @@ void EditorFileSystem::_update_script_documentation() {
update_script_paths_documentation.clear();
}
+bool EditorFileSystem::_should_reload_script(const String &p_path) {
+ if (first_scan) {
+ return false;
+ }
+
+ Ref<Script> scr = ResourceCache::get_ref(p_path);
+ if (scr.is_null()) {
+ // Not a script or not already loaded.
+ return false;
+ }
+
+ // Scripts are reloaded via the script editor if they are currently opened.
+ if (ScriptEditor::get_singleton()->get_open_scripts().has(scr)) {
+ return false;
+ }
+
+ return true;
+}
+
void EditorFileSystem::_process_update_pending() {
_update_script_classes();
// Parse documentation second, as it requires the class names to be loaded