Skip to content

Commit aeaafba

Browse files
Jondolfalice-i-cecileSpecificProtagonist
authored andcommitted
Link to required components docs in component type docs (#16687)
# Objective #16575 moved required component docs from the `Component` impl to type docs. However, it doesn't actually link to what [required components](https://docs.rs/bevy/0.15.0/bevy/ecs/component/trait.Component.html#required-components) are and how they work. ## Solution Link to [required components](https://docs.rs/bevy/0.15.0/bevy/ecs/component/trait.Component.html#required-components)! ## Testing I tested the link for some components in different Bevy crates. I did not test in external third party crates, but I would assume that it should work there too. --- ## Showcase ![Link to required components](https://github.com/user-attachments/assets/888837dd-29a1-4092-be20-c7c6f0910174) Note: The tooltip doesn't show the `#required-components` anchor for some reason, but it is there. --------- Co-authored-by: Alice Cecile <[email protected]> Co-authored-by: SpecificProtagonist <[email protected]>
1 parent 5442cf5 commit aeaafba

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

crates/bevy_ecs/macros/src/component.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,19 @@ pub fn document_required_components(attr: TokenStream, item: TokenStream) -> Tok
174174
.collect::<Vec<_>>()
175175
.join(", ");
176176

177+
let bevy_ecs_path = crate::bevy_ecs_path()
178+
.to_token_stream()
179+
.to_string()
180+
.replace(' ', "");
181+
let required_components_path = bevy_ecs_path + "::component::Component#required-components";
182+
177183
// Insert information about required components after any existing doc comments
178184
let mut out = TokenStream::new();
179185
let mut end_of_attributes_reached = false;
180186
for tt in item {
181187
if !end_of_attributes_reached & matches!(tt, TokenTree::Ident(_)) {
182188
end_of_attributes_reached = true;
183-
let doc: TokenStream = format!("#[doc = \"\n\n# Required Components\n{paths} \n\n A component's required components are inserted whenever it is inserted. Note that this will also insert the required components _of_ the required components, recursively, in depth-first order.\"]").parse().unwrap();
189+
let doc: TokenStream = format!("#[doc = \"\n\n# Required Components\n{paths} \n\n A component's [required components]({required_components_path}) are inserted whenever it is inserted. Note that this will also insert the required components _of_ the required components, recursively, in depth-first order.\"]").parse().unwrap();
184190
out.extend(doc);
185191
}
186192
out.extend(Some(tt));

0 commit comments

Comments
 (0)