Skip to content

Commit

Permalink
C#: paramref now properly tagged in documentation
Browse files Browse the repository at this point in the history
• If part of a signal, the old documentation style is used, as it points to a delegate & doesn't have actual parameters to reference
  • Loading branch information
Repiteo committed Aug 14, 2023
1 parent c495eb5 commit 10cc461
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
23 changes: 19 additions & 4 deletions modules/mono/editor/bindings_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ static String fix_doc_description(const String &p_bbcode) {
.strip_edges();
}

String BindingsGenerator::bbcode_to_xml(const String &p_bbcode, const TypeInterface *p_itype) {
String BindingsGenerator::bbcode_to_xml(const String &p_bbcode, const TypeInterface *p_itype, bool p_is_signal) {
// Based on the version in EditorHelp

if (p_bbcode.is_empty()) {
Expand Down Expand Up @@ -305,11 +305,11 @@ String BindingsGenerator::bbcode_to_xml(const String &p_bbcode, const TypeInterf
_append_xml_enum(xml_output, target_itype, target_cname, link_target, link_target_parts);
} else if (link_tag == "constant") {
_append_xml_constant(xml_output, target_itype, target_cname, link_target, link_target_parts);
} else if (link_tag == "param") {
_append_xml_param(xml_output, link_target, p_is_signal);
} else if (link_tag == "theme_item") {
// We do not declare theme_items in any way in C#, so there is nothing to reference
_append_xml_undeclared(xml_output, link_target);
} else if (link_tag == "param") {
_append_xml_undeclared(xml_output, snake_to_camel_case(link_target, false));
}

pos = brk_end + 1;
Expand Down Expand Up @@ -736,6 +736,21 @@ void BindingsGenerator::_append_xml_constant_in_global_scope(StringBuilder &p_xm
}
}

void BindingsGenerator::_append_xml_param(StringBuilder &p_xml_output, const String &p_link_target, bool p_is_signal) {
const String link_target = snake_to_camel_case(p_link_target);

if (!p_is_signal) {
p_xml_output.append("<paramref name=\"");
p_xml_output.append(link_target);
p_xml_output.append("\"/>");
} else {
// Documentation in C# is added to an event, not the delegate itself;
// as such, we treat these parameters as codeblocks instead.
// See: https://github.com/godotengine/godot/pull/65529
_append_xml_undeclared(p_xml_output, link_target);
}
}

void BindingsGenerator::_append_xml_undeclared(StringBuilder &p_xml_output, const String &p_link_target) {
p_xml_output.append("<c>");
p_xml_output.append(p_link_target);
Expand Down Expand Up @@ -2390,7 +2405,7 @@ Error BindingsGenerator::_generate_cs_signal(const BindingsGenerator::TypeInterf
}

if (p_isignal.method_doc && p_isignal.method_doc->description.size()) {
String xml_summary = bbcode_to_xml(fix_doc_description(p_isignal.method_doc->description), &p_itype);
String xml_summary = bbcode_to_xml(fix_doc_description(p_isignal.method_doc->description), &p_itype, true);
Vector<String> summary_lines = xml_summary.length() ? xml_summary.split("\n") : Vector<String>();

if (summary_lines.size()) {
Expand Down
3 changes: 2 additions & 1 deletion modules/mono/editor/bindings_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -751,14 +751,15 @@ class BindingsGenerator {
return p_type->name;
}

String bbcode_to_xml(const String &p_bbcode, const TypeInterface *p_itype);
String bbcode_to_xml(const String &p_bbcode, const TypeInterface *p_itype, bool p_is_signal = false);

void _append_xml_method(StringBuilder &p_xml_output, const TypeInterface *p_target_itype, const StringName &p_target_cname, const String &p_link_target, const Vector<String> &p_link_target_parts);
void _append_xml_member(StringBuilder &p_xml_output, const TypeInterface *p_target_itype, const StringName &p_target_cname, const String &p_link_target, const Vector<String> &p_link_target_parts);
void _append_xml_signal(StringBuilder &p_xml_output, const TypeInterface *p_target_itype, const StringName &p_target_cname, const String &p_link_target, const Vector<String> &p_link_target_parts);
void _append_xml_enum(StringBuilder &p_xml_output, const TypeInterface *p_target_itype, const StringName &p_target_cname, const String &p_link_target, const Vector<String> &p_link_target_parts);
void _append_xml_constant(StringBuilder &p_xml_output, const TypeInterface *p_target_itype, const StringName &p_target_cname, const String &p_link_target, const Vector<String> &p_link_target_parts);
void _append_xml_constant_in_global_scope(StringBuilder &p_xml_output, const String &p_target_cname, const String &p_link_target);
void _append_xml_param(StringBuilder &p_xml_output, const String &p_link_target, bool p_is_signal);
void _append_xml_undeclared(StringBuilder &p_xml_output, const String &p_link_target);

int _determine_enum_prefix(const EnumInterface &p_ienum);
Expand Down

0 comments on commit 10cc461

Please sign in to comment.