summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorIgnacio Roldán Etcheverry <neikeq@users.noreply.github.com>2022-02-11 14:51:57 +0100
committerGitHub <noreply@github.com>2022-02-11 14:51:57 +0100
commitf4478843cafc7577dc73911921e49204210acbac (patch)
treec1551ea655f62ea43d2f7d3c5e377abe558e6497 /modules
parentc5760759723491768fd44f5efc85925ca2b45b88 (diff)
parentf380a8e0ec89625274e3362d72c328012a138ff7 (diff)
Merge pull request #57917 from raulsntos/csharp-signal-documentation
Support signals in C# generated documentation
Diffstat (limited to 'modules')
-rw-r--r--modules/mono/editor/bindings_generator.cpp45
-rw-r--r--modules/mono/editor/bindings_generator.h24
2 files changed, 58 insertions, 11 deletions
diff --git a/modules/mono/editor/bindings_generator.cpp b/modules/mono/editor/bindings_generator.cpp
index 1de41821f9..f345dff333 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<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);
diff --git a/modules/mono/editor/bindings_generator.h b/modules/mono/editor/bindings_generator.h
index 2e6ce3a952..5460f018f0 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;
}