From 3f2ef8d9c2d85c6dbe4de05a442eeca39e48346e 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 | 8 + editor/doc_tools.h | 1 + editor/editor_file_system.cpp | 3 +- editor/editor_help.cpp | 221 ++++++++++++++++++++---- editor/editor_help.h | 26 ++- editor/editor_node.cpp | 10 +- editor/plugins/script_editor_plugin.cpp | 72 ++++---- scene/resources/shader.cpp | 2 +- 8 files changed, 269 insertions(+), 74 deletions(-) diff --git a/editor/doc_tools.cpp b/editor/doc_tools.cpp index 79e0c7ebd1bc..41ba0a7b966c 100644 --- a/editor/doc_tools.cpp +++ b/editor/doc_tools.cpp @@ -369,6 +369,14 @@ 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); + } + } +} + 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 87053acfb612..f278da98e960 100644 --- a/editor/editor_file_system.cpp +++ b/editor/editor_file_system.cpp @@ -1959,6 +1959,7 @@ void EditorFileSystem::_update_script_documentation() { if (!efd || index < 0) { // The file was removed + EditorHelp::remove_script_doc_by_path(path); continue; } @@ -1979,7 +1980,7 @@ void EditorFileSystem::_update_script_documentation() { } Vector docs = scr->get_documentation(); for (int j = 0; j < docs.size(); j++) { - EditorHelp::get_doc_data()->add_doc(docs[j]); + EditorHelp::add_doc(docs[j]); if (!first_scan) { // Update the documentation in the Script Editor if it is open. ScriptEditor::get_singleton()->update_doc(docs[j].name); diff --git a/editor/editor_help.cpp b/editor/editor_help.cpp index cfe257fcfc8d..5ed6c9573728 100644 --- a/editor/editor_help.cpp +++ b/editor/editor_help.cpp @@ -34,11 +34,13 @@ #include "core/core_constants.h" #include "core/extension/gdextension.h" #include "core/input/input.h" +#include "core/io/dir_access.h" #include "core/object/script_language.h" #include "core/os/keyboard.h" #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,32 +114,12 @@ 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