Merge pull request #57917 from raulsntos/csharp-signal-documentation

Support signals in C# generated documentation
This commit is contained in:
Ignacio Roldán Etcheverry 2022-02-11 14:51:57 +01:00 committed by GitHub
commit f4478843ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 58 additions and 11 deletions

View File

@ -279,8 +279,9 @@ String BindingsGenerator::bbcode_to_xml(const String &p_bbcode, const TypeInterf
xml_output.append("[");
pos = brk_pos + 1;
} else if (tag.begins_with("method ") || tag.begins_with("member ") || tag.begins_with("signal ") || tag.begins_with("enum ") || tag.begins_with("constant ")) {
String link_target = tag.substr(tag.find(" ") + 1, tag.length());
String link_tag = tag.substr(0, tag.find(" "));
const int tag_end = tag.find(" ");
const String link_tag = tag.substr(0, tag_end);
const String link_target = tag.substr(tag_end + 1, tag.length()).lstrip(" ");
Vector<String> link_target_parts = link_target.split(".");
@ -360,12 +361,38 @@ String BindingsGenerator::bbcode_to_xml(const String &p_bbcode, const TypeInterf
}
}
} else if (link_tag == "signal") {
// We do not declare signals in any way in C#, so there is nothing to reference
xml_output.append("<c>");
xml_output.append(link_target);
xml_output.append("</c>");
if (!target_itype || !target_itype->is_object_type) {
if (OS::get_singleton()->is_stdout_verbose()) {
if (target_itype) {
OS::get_singleton()->print("Cannot resolve signal reference for non-Godot.Object type in documentation: %s\n", link_target.utf8().get_data());
} else {
OS::get_singleton()->print("Cannot resolve type from signal reference in documentation: %s\n", link_target.utf8().get_data());
}
}
// TODO Map what we can
xml_output.append("<c>");
xml_output.append(link_target);
xml_output.append("</c>");
} else {
const SignalInterface *target_isignal = target_itype->find_signal_by_name(target_cname);
if (target_isignal) {
xml_output.append("<see cref=\"" BINDINGS_NAMESPACE ".");
xml_output.append(target_itype->proxy_name);
xml_output.append(".");
xml_output.append(target_isignal->proxy_name);
xml_output.append("\"/>");
} else {
ERR_PRINT("Cannot resolve signal reference in documentation: '" + link_target + "'.");
xml_output.append("<c>");
xml_output.append(link_target);
xml_output.append("</c>");
}
}
} else if (link_tag == "enum") {
StringName search_cname = !target_itype ? target_cname : StringName(target_itype->name + "." + (String)target_cname);
const StringName search_cname = !target_itype ? target_cname : StringName(target_itype->name + "." + (String)target_cname);
const Map<StringName, TypeInterface>::Element *enum_match = enum_types.find(search_cname);
@ -401,7 +428,7 @@ String BindingsGenerator::bbcode_to_xml(const String &p_bbcode, const TypeInterf
xml_output.append(link_target);
xml_output.append("</c>");
} else if (!target_itype && target_cname == name_cache.type_at_GlobalScope) {
String target_name = (String)target_cname;
const String target_name = (String)target_cname;
// Try to find as a global constant
const ConstantInterface *target_iconst = find_constant_by_name(target_name, global_constants);
@ -438,7 +465,7 @@ String BindingsGenerator::bbcode_to_xml(const String &p_bbcode, const TypeInterf
}
}
} else {
String target_name = (String)target_cname;
const String target_name = (String)target_cname;
// Try to find the constant in the current class
const ConstantInterface *target_iconst = find_constant_by_name(target_name, target_itype->constants);

View File

@ -366,6 +366,16 @@ class BindingsGenerator {
return nullptr;
}
const MethodInterface *find_method_by_proxy_name(const String &p_proxy_name) const {
for (const MethodInterface &E : methods) {
if (E.proxy_name == p_proxy_name) {
return &E;
}
}
return nullptr;
}
const PropertyInterface *find_property_by_name(const StringName &p_cname) const {
for (const PropertyInterface &E : properties) {
if (E.cname == p_cname) {
@ -386,8 +396,18 @@ class BindingsGenerator {
return nullptr;
}
const MethodInterface *find_method_by_proxy_name(const String &p_proxy_name) const {
for (const MethodInterface &E : methods) {
const SignalInterface *find_signal_by_name(const StringName &p_cname) const {
for (const SignalInterface &E : signals_) {
if (E.cname == p_cname) {
return &E;
}
}
return nullptr;
}
const SignalInterface *find_signal_by_proxy_name(const String &p_proxy_name) const {
for (const SignalInterface &E : signals_) {
if (E.proxy_name == p_proxy_name) {
return &E;
}