summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDanil Alexeev <danil@alexeev.xyz>2024-01-20 23:11:55 +0300
committerDanil Alexeev <danil@alexeev.xyz>2024-01-21 11:28:23 +0300
commit5e7cda3405b82f70f8d832a70b7ac64c9c1ec2f6 (patch)
tree1463f9012982f31af724338318fb9a6542d2dfbb
parent0bcc0e92b3f0ac57d4c4650722f347593a258572 (diff)
downloadredot-engine-5e7cda3405b82f70f8d832a70b7ac64c9c1ec2f6.tar.gz
GDScript: Use autoload singleton name in `GDScriptDocGen`
-rw-r--r--modules/gdscript/editor/gdscript_docgen.cpp49
-rw-r--r--modules/gdscript/editor/gdscript_docgen.h5
2 files changed, 38 insertions, 16 deletions
diff --git a/modules/gdscript/editor/gdscript_docgen.cpp b/modules/gdscript/editor/gdscript_docgen.cpp
index 00179109a3..659140b9b1 100644
--- a/modules/gdscript/editor/gdscript_docgen.cpp
+++ b/modules/gdscript/editor/gdscript_docgen.cpp
@@ -32,21 +32,29 @@
#include "../gdscript.h"
-String GDScriptDocGen::_get_script_path(const String &p_path) {
+#include "core/config/project_settings.h"
+
+HashMap<String, String> GDScriptDocGen::singletons;
+
+String GDScriptDocGen::_get_script_name(const String &p_path) {
+ const HashMap<String, String>::ConstIterator E = singletons.find(p_path);
+ if (E) {
+ return E->value;
+ }
return p_path.trim_prefix("res://").quote();
}
String GDScriptDocGen::_get_class_name(const GDP::ClassNode &p_class) {
const GDP::ClassNode *curr_class = &p_class;
if (!curr_class->identifier) { // All inner classes have an identifier, so this is the outer class.
- return _get_script_path(curr_class->fqcn);
+ return _get_script_name(curr_class->fqcn);
}
String full_name = curr_class->identifier->name;
while (curr_class->outer) {
curr_class = curr_class->outer;
if (!curr_class->identifier) { // All inner classes have an identifier, so this is the outer class.
- return vformat("%s.%s", _get_script_path(curr_class->fqcn), full_name);
+ return vformat("%s.%s", _get_script_name(curr_class->fqcn), full_name);
}
full_name = vformat("%s.%s", curr_class->identifier->name, full_name);
}
@@ -97,12 +105,12 @@ void GDScriptDocGen::_doctype_from_gdtype(const GDType &p_gdtype, String &r_type
return;
}
if (!p_gdtype.script_type->get_path().is_empty()) {
- r_type = _get_script_path(p_gdtype.script_type->get_path());
+ r_type = _get_script_name(p_gdtype.script_type->get_path());
return;
}
}
if (!p_gdtype.script_path.is_empty()) {
- r_type = _get_script_path(p_gdtype.script_path);
+ r_type = _get_script_name(p_gdtype.script_path);
return;
}
r_type = "Object";
@@ -221,24 +229,25 @@ String GDScriptDocGen::_docvalue_from_variant(const Variant &p_variant, int p_re
}
}
-void GDScriptDocGen::generate_docs(GDScript *p_script, const GDP::ClassNode *p_class) {
+void GDScriptDocGen::_generate_docs(GDScript *p_script, const GDP::ClassNode *p_class) {
p_script->_clear_doc();
DocData::ClassDoc &doc = p_script->doc;
- doc.script_path = _get_script_path(p_script->get_script_path());
+ doc.is_script_doc = true;
+
if (p_script->local_name == StringName()) {
- doc.name = doc.script_path;
+ // This is an outer unnamed class.
+ doc.name = _get_script_name(p_script->get_script_path());
} else {
+ // This is an inner or global outer class.
doc.name = p_script->local_name;
+ if (p_script->_owner) {
+ doc.name = p_script->_owner->doc.name + "." + doc.name;
+ }
}
- if (p_script->_owner) {
- doc.name = p_script->_owner->doc.name + "." + doc.name;
- doc.script_path = doc.script_path + "." + doc.name;
- }
-
- doc.is_script_doc = true;
+ doc.script_path = p_script->get_script_path();
if (p_script->base.is_valid() && p_script->base->is_valid()) {
if (!p_script->base->doc.name.is_empty()) {
@@ -271,7 +280,7 @@ void GDScriptDocGen::generate_docs(GDScript *p_script, const GDP::ClassNode *p_c
// Recursively generate inner class docs.
// Needs inner GDScripts to exist: previously generated in GDScriptCompiler::make_scripts().
- GDScriptDocGen::generate_docs(*p_script->subclasses[class_name], inner_class);
+ GDScriptDocGen::_generate_docs(*p_script->subclasses[class_name], inner_class);
} break;
case GDP::ClassNode::Member::CONSTANT: {
@@ -451,3 +460,13 @@ void GDScriptDocGen::generate_docs(GDScript *p_script, const GDP::ClassNode *p_c
// Add doc to the outer-most class.
p_script->_add_doc(doc);
}
+
+void GDScriptDocGen::generate_docs(GDScript *p_script, const GDP::ClassNode *p_class) {
+ for (const KeyValue<StringName, ProjectSettings::AutoloadInfo> &E : ProjectSettings::get_singleton()->get_autoload_list()) {
+ if (E.value.is_singleton) {
+ singletons[E.value.path] = E.key;
+ }
+ }
+ _generate_docs(p_script, p_class);
+ singletons.clear();
+}
diff --git a/modules/gdscript/editor/gdscript_docgen.h b/modules/gdscript/editor/gdscript_docgen.h
index a326c02c5f..651a4fb198 100644
--- a/modules/gdscript/editor/gdscript_docgen.h
+++ b/modules/gdscript/editor/gdscript_docgen.h
@@ -39,10 +39,13 @@ class GDScriptDocGen {
using GDP = GDScriptParser;
using GDType = GDP::DataType;
- static String _get_script_path(const String &p_path);
+ static HashMap<String, String> singletons; // Script path to singleton name.
+
+ static String _get_script_name(const String &p_path);
static String _get_class_name(const GDP::ClassNode &p_class);
static void _doctype_from_gdtype(const GDType &p_gdtype, String &r_type, String &r_enum, bool p_is_return = false);
static String _docvalue_from_variant(const Variant &p_variant, int p_recursion_level = 1);
+ static void _generate_docs(GDScript *p_script, const GDP::ClassNode *p_class);
public:
static void generate_docs(GDScript *p_script, const GDP::ClassNode *p_class);