Skip to content

Move required components doc to type doc#16575

Merged
alice-i-cecile merged 5 commits intobevyengine:mainfrom
SpecificProtagonist:better-required-components-doc
Dec 3, 2024
Merged

Move required components doc to type doc#16575
alice-i-cecile merged 5 commits intobevyengine:mainfrom
SpecificProtagonist:better-required-components-doc

Conversation

@SpecificProtagonist
Copy link
Copy Markdown
Contributor

@SpecificProtagonist SpecificProtagonist commented Nov 30, 2024

Objective

Make documentation of a component's required components more visible by moving it to the type's docs

Solution

Change #[require] from a derive macro helper to an attribute macro.

Disadvantages:

  • this silences any unused code warnings on the component, as it is used by the macro!
  • need to import require if not using the ecs prelude (I have not included this in the migration guilde as Rust tooling already suggests the fix)

Showcase

Documentation of Camera

@alice-i-cecile alice-i-cecile added C-Docs An addition or correction to our documentation A-ECS Entities, components, systems, and events X-Contentious There are nontrivial implications that should be thought through S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Nov 30, 2024
@alice-i-cecile alice-i-cecile requested a review from cart November 30, 2024 21:37
@alice-i-cecile
Copy link
Copy Markdown
Member

Neat, I had no idea this would work. I prefer this: I think it's more discoverable.

@Jondolf
Copy link
Copy Markdown
Contributor

Jondolf commented Nov 30, 2024

This should probably have a heading or a horizontal rule separating the section from the rest of the docs. Currenly it blends in too much, and sometimes looks like it's a part of some other text even though it should be separate.

See image

docs

With a horizontal rule (just using \n\n---\n\nRequired Components: {paths}), it looks like this:

See image

docs

I think this might be a clear enough separation between "type docs" and "docs automatically embedded by Bevy".

We could also use a heading, which would look like this:

See image

docs

The benefit here is that it shows up in the Sections outline on the left, so it's quicker to navigate to the Required Components section for components with long docs. You can also link to the heading, which could be nice so that you can send a direct link if people are asking about a specific component's required components for whatever reason.

The (minor) downside of the heading is that it must be a top-level h1 heading, because otherwise it could be shown "beneath" other sections in the outline, which would be wrong. Being an h1 heading makes it quite prominent, for better or for worse.

I think I'm mildly in favor of the heading because of it being shown in the outline, being linkable, and overall looking cleaner, but the horizontal rule could work fine too.

Edit: Made the images collapsible since they were taking so much space :P

@Jondolf
Copy link
Copy Markdown
Contributor

Jondolf commented Nov 30, 2024

By the way, if anyone is wondering if these auto-generated docs show up in VSCode when hovering over a type, they do!

VSCode hover docs

@alice-i-cecile
Copy link
Copy Markdown
Member

@SpecificProtagonist I'm very much interested in this: can you make sure CI is green and then ping me for final review?

@SpecificProtagonist
Copy link
Copy Markdown
Contributor Author

@alice-i-cecile

@Jondolf
Copy link
Copy Markdown
Contributor

Jondolf commented Dec 2, 2024

Oh wow, another nice side effect here is that this makes autocomplete for require work!

autocomplete!!!

Previously you got no suggestions and had to remember if it's require or requires. I saw a few people complaining about that on Discord earlier

@Jondolf Jondolf added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Dec 2, 2024
@SpecificProtagonist
Copy link
Copy Markdown
Contributor Author

Previously you got no suggestions and had to remember if it's require or requires

Huh, I can confirm that. Sounds like a missing Rust-Analyzer feature (or a bug) - the information is available in derive macro declaration. I'll open an issue in the RA repo (and maybe try to fix it myself).

Co-authored-by: JMS55 <[email protected]>
Merged via the queue into bevyengine:main with commit d92fc1e Dec 3, 2024
@BD103 BD103 added the M-Release-Note Work that should be called out in the blog due to impact label Dec 4, 2024
@BD103
Copy link
Copy Markdown
Member

BD103 commented Dec 4, 2024

I'd like to nominate this for release notes. I think this feature is going to be very valuable to users migrating to required components, especially when it comes to visibility in libraries and plugins.

github-merge-queue bot pushed a commit that referenced this pull request Dec 10, 2024
# 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]>
BD103 pushed a commit to BD103/bevy that referenced this pull request Dec 10, 2024
…6687)

# Objective

bevyengine#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]>
ecoskey pushed a commit to ecoskey/bevy that referenced this pull request Jan 6, 2025
# Objective

Make documentation of a component's required components more visible by
moving it to the type's docs

## Solution

Change `#[require]` from a derive macro helper to an attribute macro.

Disadvantages:
- this silences any unused code warnings on the component, as it is used
by the macro!
- need to import `require` if not using the ecs prelude (I have not
included this in the migration guilde as Rust tooling already suggests
the fix)

---

## Showcase
![Documentation of
Camera](https://github.com/user-attachments/assets/3329511b-747a-4c8d-a43e-57f7c9c71a3c)

---------

Co-authored-by: Alice Cecile <[email protected]>
Co-authored-by: JMS55 <[email protected]>
ecoskey pushed a commit to ecoskey/bevy that referenced this pull request Jan 6, 2025
…6687)

# Objective

bevyengine#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]>
github-merge-queue bot pushed a commit that referenced this pull request Mar 6, 2025
# Objective

Component `require()` IDE integration is fully broken, as of #16575.

## Solution

This reverts us back to the previous "put the docs on Component trait"
impl. This _does_ reduce the accessibility of the required components in
rust docs, but the complete erasure of "required component IDE
experience" is not worth the price of slightly increased prominence of
requires in docs.

Additionally, Rust Analyzer has recently started including derive
attributes in suggestions, so we aren't losing that benefit of the
proc_macro attribute impl.
@alice-i-cecile
Copy link
Copy Markdown
Member

Thank you to everyone involved with the authoring or reviewing of this PR! This work is relatively important and needs release notes! Head over to bevyengine/bevy-website#1962 if you'd like to help out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ECS Entities, components, systems, and events C-Docs An addition or correction to our documentation M-Release-Note Work that should be called out in the blog due to impact S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it X-Contentious There are nontrivial implications that should be thought through

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants