Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trait tags on docs.rs #17758

Merged

Conversation

SpecificProtagonist
Copy link
Contributor

@SpecificProtagonist SpecificProtagonist commented Feb 9, 2025

Objective

Bevy's ECS provides several core traits such as Component, SystemParam, etc that determine where a type can be used. When reading the docs, this currently requires scrolling down to and scanning the "Trait Implementations" section. Make these core traits more visible.

Solution

Add a color-coded labels below the type heading denoting the following types:

  • Component
    • immutable components are labeled as such
  • Resource
  • Asset
  • Event
  • Plugin & PluginGroup
  • ScheduleLabel & SystemSet
  • SystemParam

As docs.rs does not provide an option for post-processing the html, these are added via JS with traits implementations being detected by scanning the DOM. Rustdoc's html output is unstable, which could potentially lead to this detection (or the adding of the labels) to break, however it only needs to work when a new release is deployed and falls back to the status quo of not displaying these labels.

Idea by JMS55, implementation by Jondolf (see https://github.com/Jondolf/bevy_docs_extension_demo/).

Testing

Run this in Bevy's root folder:

 RUSTDOCFLAGS="--html-after-content docs-rs/trait-tags.html --cfg docsrs_dep" RUSTFLAGS="--cfg docsrs_dep" cargo doc --no-deps -p <some_bevy_package>

Showcase

Check it out on docs.rs

trait tags

Release Notes

On docs.rs, Bevy now displays labels indicating which core traits a type implements:
trait tags small

If you want to add these to your own crate, check out these instructions.

@SpecificProtagonist SpecificProtagonist added C-Docs An addition or correction to our documentation S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Feb 9, 2025
@alice-i-cecile alice-i-cecile added A-ECS Entities, components, systems, and events M-Needs-Release-Note Work that should be called out in the blog due to impact labels Feb 9, 2025
@alice-i-cecile
Copy link
Member

I love the end result. I'll let others chime in on the impl though.

@alice-i-cecile alice-i-cecile added this to the 0.16 milestone Feb 9, 2025
Copy link
Member

@BD103 BD103 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good! I'm not sure I like creating a new root-level folder, but there are no better alternatives right now. Thank you, this is really cool!

@SpecificProtagonist
Copy link
Contributor Author

SpecificProtagonist commented Feb 11, 2025

I'm not sure I like creating a new root-level folder, but there are no better alternatives right now.

I considered putting it in docs/, but that doesn't fit as it affects generated docs instead of being documentation like the rest of that folder.

Putting this in tools/ should make sense though, no?

@BD103
Copy link
Member

BD103 commented Feb 11, 2025

I'm not sure I like creating a new root-level folder, but there are no better alternatives right now.

I considered putting it in docs/, but that doesn't fit as it affects generated docs instead of being documentation like the rest of that folder.

Putting this in tools/ should make sense though, no?

It should! In the future it may be worth combining a lot of the root folders we have into something like etc, but for now I'd be happy with either docs-rs or tools.

@SpecificProtagonist
Copy link
Contributor Author

The entries in tools currently are automatically members of the cargo workspace, so I think I'll stay with docs-rs.

@mockersf
Copy link
Member

@SpecificProtagonist
Copy link
Contributor Author

could you add the new flags to https://github.com/bevyengine/bevy/blob/main/.github/workflows/docs.yml#L64?

Thanks, lost that change when splitting apart the PR.

@SpecificProtagonist SpecificProtagonist 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 Feb 11, 2025
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Feb 11, 2025
Merged via the queue into bevyengine:main with commit 5b0d898 Feb 11, 2025
34 checks passed
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-Needs-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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants