Is there "format off" and "format on" comment commands in VSCode?

Hi, is there similar "format off" or "format on" comment commands in Rust that there is in clang-format? E.g. like " The code between a comment // clang-format off or / clang-format off / up to a comment // clang-format on or / clang-format on / will not be formatted .".

Edit: I have some unit test "data" and etc. in the test function I don't want Rust Analyzer to format...

AFAIK there is no comment-based equivalent in rustfmt. However, you can use the #[rustfmt::skip] attribute to annotate elements you don't want to be formatted.

1 Like

Ok, so I need one attribute per element, e.g., there's no these kind of "block" attributes. This is at least better than nothing, thank you.

You can apply #[rustfmt::skip] to block expressions or whole modules if that'd help you.

3 Likes