Skip to content

Commit 587ce16

Browse files
committed
Add GDScript note to beginning of file, only show method-level note for methods with code blocks
1 parent 7ad70e9 commit 587ce16

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

bindings_generator/src/class_docs.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,19 +124,29 @@ impl GodotXMLDocs {
124124
}
125125
}
126126

127-
self.class_fn_desc
128-
.insert((class.into(), method.into()), Self::reformat_as_rustdoc(doc));
127+
self.class_fn_desc.insert(
128+
(class.into(), method.into()),
129+
Self::reformat_as_rustdoc(doc),
130+
);
129131
}
130132

131133
/// Takes the Godot documentation markup and transforms it to Rustdoc.
132134
/// Very basic approach with limitations, but already helps readability quite a bit.
133135
fn reformat_as_rustdoc(godot_doc: String) -> String {
134-
godot_doc
136+
let gdscript_note = if godot_doc.contains("[codeblock]") {
137+
"_Sample code is GDScript unless otherwise noted._\n\n"
138+
} else {
139+
""
140+
};
141+
142+
let translated = godot_doc
135143
.replace("[code]", "`")
136144
.replace("[/code]", "`")
137145
.replace("[codeblock]", "```gdscript")
138146
.replace("[/codeblock]", "```")
139147
.replace("[b]", "**")
140-
.replace("[/b]", "**")
148+
.replace("[/b]", "**");
149+
150+
format!("{}{}", gdscript_note, translated)
141151
}
142152
}

bindings_generator/src/documentation.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ pub fn generate_class_documentation(api: &Api, class: &GodotClass) -> TokenStrea
5252
let official_docs = format!(
5353
r#"## Official documentation
5454
55-
See the [documentation of this class]({url}) in the Godot engine's official documentation."#,
55+
See the [documentation of this class]({url}) in the Godot engine's official documentation.
56+
The method descriptions are generated from it and typically contain code samples in GDScript, not Rust."#,
5657
url = official_doc_url(class),
5758
);
5859

0 commit comments

Comments
 (0)