Sometimes Rust Analyzer stops formatting my VS Code document and there is no message or explanation why.
This is just one ugly example - lines 46-53 are all over the place.
No matter how many times I press
I the IDE would not fix the formatting or tell me what's wrong.
Turns out there is a simple way to find out why Rust Analyzer fails to format the document:
cargo fmt. It will tell you exactly what's broken.
In this case it was a comment on line 44 that got in the way. The document started formatting again as soon as I removed it.
cargo fmtwill attempt to reformat the entire project. Read more about it in https://github.com/rust-lang/rustfmt or run
cargo fmt -- --helpfor options.
I went back to several other files that were not formatting properly, ran
cargo fmt on them and quickly fixed the problems. Happy coding!
Top comments (1)
Thank you for figuring this out 🙏