From f380a8e0ec89625274e3362d72c328012a138ff7 Mon Sep 17 00:00:00 2001 From: Raul Santos Date: Wed, 9 Feb 2022 19:01:18 +0100 Subject: [PATCH] Support signals in C# documentation --- modules/mono/editor/bindings_generator.cpp | 45 +++++++++++++++++----- modules/mono/editor/bindings_generator.h | 24 +++++++++++- 2 files changed, 58 insertions(+), 11 deletions(-) diff --git a/modules/mono/editor/bindings_generator.cpp b/modules/mono/editor/bindings_generator.cpp index 1de41821f9c..f345dff3330 100644 --- a/modules/mono/editor/bindings_generator.cpp +++ b/modules/mono/editor/bindings_generator.cpp @@ -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 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(""); - xml_output.append(link_target); - xml_output.append(""); + 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(""); + xml_output.append(link_target); + xml_output.append(""); + } else { + const SignalInterface *target_isignal = target_itype->find_signal_by_name(target_cname); + + if (target_isignal) { + xml_output.append("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(""); + xml_output.append(link_target); + xml_output.append(""); + } + } } 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::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(""); } 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); diff --git a/modules/mono/editor/bindings_generator.h b/modules/mono/editor/bindings_generator.h index 2e6ce3a952e..5460f018f05 100644 --- a/modules/mono/editor/bindings_generator.h +++ b/modules/mono/editor/bindings_generator.h @@ -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; }