From 72045c8306ed9bc021b42593755b536c526f3239 Mon Sep 17 00:00:00 2001 From: ocean Date: Mon, 19 Aug 2024 17:03:03 -0400 Subject: [PATCH] Scripting: Add script documentation cache to project This PR adds a script documentation cache in the project folder. It is loaded at alongside native documentation caches. This makes scripts fully accessible through Search Help, including their members, etc, right from project start, without having to compile every single script. Co-authored-by: Hilderin <81109165+Hilderin@users.noreply.github.com> --- editor/doc_tools.cpp | 9 + editor/doc_tools.h | 1 + editor/editor_file_system.cpp | 3 +- editor/editor_help.cpp | 374 +++++++++++++++++------- editor/editor_help.h | 43 ++- editor/editor_node.cpp | 6 +- editor/plugins/script_editor_plugin.cpp | 66 ++--- scene/resources/shader.cpp | 4 +- 8 files changed, 358 insertions(+), 148 deletions(-) diff --git a/editor/doc_tools.cpp b/editor/doc_tools.cpp index a3e5d775f1..c790de5bbd 100644 --- a/editor/doc_tools.cpp +++ b/editor/doc_tools.cpp @@ -368,6 +368,15 @@ void DocTools::remove_doc(const String &p_class_name) { class_list.erase(p_class_name); } +void DocTools::remove_script_doc_by_path(const String &p_path) { + for (KeyValue &E : class_list) { + if (E.value.is_script_doc && E.value.script_path == p_path) { + remove_doc(E.key); + return; + } + } +} + bool DocTools::has_doc(const String &p_class_name) { if (p_class_name.is_empty()) { return false; diff --git a/editor/doc_tools.h b/editor/doc_tools.h index 6dd9d5ebcb..fcac2c2142 100644 --- a/editor/doc_tools.h +++ b/editor/doc_tools.h @@ -44,6 +44,7 @@ public: void merge_from(const DocTools &p_data); void add_doc(const DocData::ClassDoc &p_class_doc); void remove_doc(const String &p_class_name); + void remove_script_doc_by_path(const String &p_path); bool has_doc(const String &p_class_name); enum GenerateFlags { GENERATE_FLAG_SKIP_BASIC_TYPES = (1 << 0), diff --git a/editor/editor_file_system.cpp b/editor/editor_file_system.cpp index 16a7578d8a..0a4468dc9c 100644 --- a/editor/editor_file_system.cpp +++ b/editor/editor_file_system.cpp @@ -2171,6 +2171,7 @@ void EditorFileSystem::_update_script_documentation() { if (!efd || index < 0) { // The file was removed + EditorHelp::remove_script_doc_by_path(path); continue; } @@ -2188,7 +2189,7 @@ void EditorFileSystem::_update_script_documentation() { scr->reload_from_file(); } for (const DocData::ClassDoc &cd : scr->get_documentation()) { - EditorHelp::get_doc_data()->add_doc(cd); + EditorHelp::add_doc(cd); if (!first_scan) { // Update the documentation in the Script Editor if it is open. ScriptEditor::get_singleton()->update_doc(cd.name); diff --git a/editor/editor_help.cpp b/editor/editor_help.cpp index 3a42405f62..bf6349ded5 100644 --- a/editor/editor_help.cpp +++ b/editor/editor_help.cpp @@ -40,6 +40,7 @@ #include "core/string/string_builder.h" #include "core/version_generated.gen.h" #include "editor/doc_data_compressed.gen.h" +#include "editor/editor_file_system.h" #include "editor/editor_main_screen.h" #include "editor/editor_node.h" #include "editor/editor_paths.h" @@ -192,37 +193,6 @@ static String _contextualize_class_specifier(const String &p_class_specifier, co /// EditorHelp /// -// TODO: This is sometimes used directly as `doc->something`, other times as `EditorHelp::get_doc_data()`, which is thread-safe. -// Might this be a problem? -DocTools *EditorHelp::doc = nullptr; -DocTools *EditorHelp::ext_doc = nullptr; - -int EditorHelp::doc_generation_count = 0; -String EditorHelp::doc_version_hash; -Thread EditorHelp::worker_thread; - -static bool _attempt_doc_load(const String &p_class) { - // Docgen always happens in the outer-most class: it also generates docs for inner classes. - const String outer_class = p_class.get_slicec('.', 0); - if (!ScriptServer::is_global_class(outer_class)) { - return false; - } - - // `ResourceLoader` is used in order to have a script-agnostic way to load scripts. - // This forces GDScript to compile the code, which is unnecessary for docgen, but it's a good compromise right now. - const Ref