From 3ebb4d315a56951b1373697fefc8083c93f651a0 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 | 299 +++++++++++++++++++----- 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, 323 insertions(+), 108 deletions(-) diff --git a/editor/doc_tools.cpp b/editor/doc_tools.cpp index 79e0c7ebd1bc..84a080f7c705 100644 --- a/editor/doc_tools.cpp +++ b/editor/doc_tools.cpp @@ -369,6 +369,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 3be59bf233cf..43d302c873c7 100644 --- a/editor/doc_tools.h +++ b/editor/doc_tools.h @@ -45,6 +45,7 @@ class DocTools { 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 2d1a91412008..91b8ec0b60a0 100644 --- a/editor/editor_file_system.cpp +++ b/editor/editor_file_system.cpp @@ -2073,6 +2073,7 @@ void EditorFileSystem::_update_script_documentation() { if (!efd || index < 0) { // The file was removed + EditorHelp::remove_script_doc_by_path(path); continue; } @@ -2090,7 +2091,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 cfe257fcfc8d..640b7b171639 100644 --- a/editor/editor_help.cpp +++ b/editor/editor_help.cpp @@ -39,6 +39,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" @@ -112,33 +113,6 @@ const Vector packed_array_types = { "PackedVector4Array", }; -// 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; - -static bool _attempt_doc_load(const String &p_class) { - // Docgen always happens in the outer-most class: it also generates docs for inner classes. - String outer_class = p_class.get_slice(".", 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. - Ref