From 5bdc0d97d35b254c6a710e95582b135ab3dcefd2 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Wed, 18 Jan 2023 17:32:28 +0100 Subject: Clean up EditorFileSystem script parsing * Optimize only update modified/added/removed files. * Clean up documentation parsing. --- core/object/script_language.cpp | 9 +++ core/object/script_language.h | 1 + doc/classes/EditorFileSystem.xml | 6 -- editor/editor_file_system.cpp | 117 ++++++++++++++++++-------------- editor/editor_file_system.h | 9 ++- editor/plugins/script_editor_plugin.cpp | 3 +- 6 files changed, 81 insertions(+), 64 deletions(-) diff --git a/core/object/script_language.cpp b/core/object/script_language.cpp index c9cfbdd4cb..66ef418e42 100644 --- a/core/object/script_language.cpp +++ b/core/object/script_language.cpp @@ -263,6 +263,15 @@ void ScriptServer::remove_global_class(const StringName &p_class) { global_classes.erase(p_class); } +void ScriptServer::remove_global_class_by_path(const String &p_path) { + for (const KeyValue &kv : global_classes) { + if (kv.value.path == p_path) { + global_classes.erase(kv.key); + return; + } + } +} + bool ScriptServer::is_global_class(const StringName &p_class) { return global_classes.has(p_class); } diff --git a/core/object/script_language.h b/core/object/script_language.h index ff678bcd25..02d1880dc2 100644 --- a/core/object/script_language.h +++ b/core/object/script_language.h @@ -80,6 +80,7 @@ public: static void global_classes_clear(); static void add_global_class(const StringName &p_class, const StringName &p_base, const StringName &p_language, const String &p_path); static void remove_global_class(const StringName &p_class); + static void remove_global_class_by_path(const String &p_path); static bool is_global_class(const StringName &p_class); static StringName get_global_class_language(const StringName &p_class); static String get_global_class_path(const String &p_class); diff --git a/doc/classes/EditorFileSystem.xml b/doc/classes/EditorFileSystem.xml index cddf3662aa..5f33c68a7d 100644 --- a/doc/classes/EditorFileSystem.xml +++ b/doc/classes/EditorFileSystem.xml @@ -71,12 +71,6 @@ This will not import the file. To reimport, call [method reimport_files] or [method scan] methods. - - - - Scans the script files and updates the list of custom class names. - - diff --git a/editor/editor_file_system.cpp b/editor/editor_file_system.cpp index 9c056ffdd9..63008ec65c 100644 --- a/editor/editor_file_system.cpp +++ b/editor/editor_file_system.cpp @@ -602,10 +602,19 @@ bool EditorFileSystem::_update_scan_actions() { fs_changed = true; + if (ClassDB::is_parent_class(ia.new_file->type, SNAME("Script"))) { + _queue_update_script_class(ia.dir->get_file_path(idx)); + } + } break; case ItemAction::ACTION_FILE_REMOVE: { int idx = ia.dir->find_file_index(ia.file); ERR_CONTINUE(idx == -1); + + if (ClassDB::is_parent_class(ia.dir->files[idx]->type, SNAME("Script"))) { + _queue_update_script_class(ia.dir->get_file_path(idx)); + } + _delete_internal_files(ia.dir->files[idx]->file); memdelete(ia.dir->files[idx]); ia.dir->files.remove_at(idx); @@ -640,6 +649,10 @@ bool EditorFileSystem::_update_scan_actions() { ERR_CONTINUE(idx == -1); String full_path = ia.dir->get_file_path(idx); + if (ClassDB::is_parent_class(ia.dir->files[idx]->type, SNAME("Script"))) { + _queue_update_script_class(full_path); + } + reloads.push_back(full_path); } break; @@ -710,7 +723,6 @@ void EditorFileSystem::scan() { scanning = false; emit_signal(SNAME("filesystem_changed")); emit_signal(SNAME("sources_changed"), sources_changed.size() > 0); - _queue_update_script_classes(); first_scan = false; } else { ERR_FAIL_COND(thread.is_started()); @@ -922,20 +934,6 @@ void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir, Refsupports_documentation() && fi->type == lang->get_type()) { - Ref