Skip to content

Bsn fmt support + cli tool#23586

Draft
NicoZweifel wants to merge 14 commits intobevyengine:mainfrom
NicoZweifel:bsn-fmt
Draft

Bsn fmt support + cli tool#23586
NicoZweifel wants to merge 14 commits intobevyengine:mainfrom
NicoZweifel:bsn-fmt

Conversation

@NicoZweifel
Copy link
Copy Markdown
Contributor

@NicoZweifel NicoZweifel commented Mar 30, 2026

Objective

Bsn fmt

Solution

Adds a bsn formatter and binary that can be used in terminals, editors or CLI tools.

Testing

There is a small readme with some instructions, you might find more there soon, currently there are only instructions on how to use it in a terminal or with nvim + conform but I might add others later, or at least the most common ones.

cargo install --path .\crates\bevy_scene2\macros --features fmt --bin bsnfmt
bsnfmt .\examples\scene\bsn.rs

Editor integration

nvim

conform

formatters_by_ft = {
    rust = { "rustfmt", "bsnfmt" },
},
formatters = {
    bsn_fmt = {
        command = "bsnfmt",
        stdin = true,
    },
},

Development

cd crates/bevy_scene2/macros && cargo watch --features fmt test fmt

Notes

  • draft for now, needs cleanup / polish and could be moved but I'd probably prefer to ship it rather than refactor out bsn types in this PR. Maybe it could be done in another PR. Either a follow-up or as a blocker for this one, but bsn types and traits etc. need to be accessible for tooling like this.
  • eventually I can see this being it's own standalone bevy fmt crate in bevy_cli but only if it is a standalone binary because that is fundamentally a requirement for editor workflows (and other things too) imo.
  • depends on bsn! macro code quality improvements: codegen, error handling, tests, docs #23561. Changes will disappear once it's merged. I can rebase and soft revert if required but I think it's probably already fine without a rebase since I already soft reverted the changes onto this branch.
  • Doesn't support comments, if there are any comments present in the bsn macro, it will fail to format. Could be added in the future but it is rather complex since syn strips out comments and as far as I know this requires either matching sourrounding areas after formatting or changes to the bsn parser itself.
Screenshot 2026-03-30 154435
Recording.2026-03-30.211926.mp4

@Jondolf Jondolf added C-Code-Quality A section of code that is hard to understand or change C-Usability A targeted quality-of-life change that makes Bevy easier to use A-Scenes Serialized ECS data stored on the disk S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels Mar 30, 2026
@alice-i-cecile alice-i-cecile requested a review from cart March 30, 2026 19:29
@cart cart moved this to Candidate in @cart's attention Mar 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Scenes Serialized ECS data stored on the disk C-Code-Quality A section of code that is hard to understand or change C-Usability A targeted quality-of-life change that makes Bevy easier to use S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged

Projects

Status: Candidate

Development

Successfully merging this pull request may close these issues.

3 participants