Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GDScript: Use autoload singleton name in GDScriptDocGen #87421

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 34 additions & 15 deletions modules/gdscript/editor/gdscript_docgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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();
}
5 changes: 4 additions & 1 deletion modules/gdscript/editor/gdscript_docgen.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading