Skip to content

Commit

Permalink
Scripting: Add script documentation cache to project
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
anvilfolk and Hilderin committed Sep 27, 2024
1 parent 76a1359 commit 65f33aa
Show file tree
Hide file tree
Showing 10 changed files with 322 additions and 111 deletions.
8 changes: 4 additions & 4 deletions editor/create_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,10 @@ void CreateDialog::_configure_search_option_item(TreeItem *r_item, const StringN
r_item->set_custom_color(0, search_options->get_theme_color(SNAME("font_disabled_color"), EditorStringName(Editor)));
}

HashMap<String, DocData::ClassDoc>::Iterator class_doc = EditorHelp::get_doc_data()->class_list.find(p_type);
const DocData::ClassDoc *class_doc = EditorHelp::get_doc(p_type);

bool is_deprecated = (class_doc && class_doc->value.is_deprecated);
bool is_experimental = (class_doc && class_doc->value.is_experimental);
bool is_deprecated = (class_doc && class_doc->is_deprecated);
bool is_experimental = (class_doc && class_doc->is_experimental);

if (is_deprecated) {
r_item->add_button(0, get_editor_theme_icon("StatusError"), 0, false, TTR("This class is marked as deprecated."));
Expand All @@ -333,7 +333,7 @@ void CreateDialog::_configure_search_option_item(TreeItem *r_item, const StringN
r_item->set_collapsed(should_collapse);
}

const String &description = DTR(class_doc ? class_doc->value.brief_description : "");
const String &description = DTR(class_doc ? class_doc->brief_description : "");
r_item->set_tooltip_text(0, description);

if (p_type_category == TypeCategory::OTHER_TYPE && !script_type) {
Expand Down
9 changes: 9 additions & 0 deletions editor/doc_tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, DocData::ClassDoc> &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;
Expand Down
1 change: 1 addition & 0 deletions editor/doc_tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
3 changes: 2 additions & 1 deletion editor/editor_file_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -2091,7 +2092,7 @@ void EditorFileSystem::_update_script_documentation() {
}
Vector<DocData::ClassDoc> 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);
Expand Down
Loading

0 comments on commit 65f33aa

Please sign in to comment.