-
Notifications
You must be signed in to change notification settings - Fork 1.7k
invoking rustfmt uses the project-wide rustfmt.toml, not the one for the current subcrate #15540
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
Comments
If I |
Hmm, when we invoke rustfmt we actually set the working directory to the containing folder of the file we are trying to format, so it should just pick up the correct config, rust-analyzer/crates/rust-analyzer/src/handlers/request.rs Lines 1897 to 1913 in 3213344
|
It looks like you are only doing that when |
Ah right, then that is in fact the issue. |
The rustc repository contains multiple rustfmt.toml files, for instance:
So, when invoking formatting via RA in a file in
src/tools/miri
, I'd hope./src/tools/miri/rustfmt.toml
would be used. But unfortunately it always uses./rustfmt.toml
, which regularly leads to people accidentally formatting Miri files in their rustc PRs with the wrong settings.This can be reproduced, for example, by opening
src/tools/miri/src/borrow_tracker/tree_borrows/mod.rs
and invoking Ctrl-Shift-I in vscode.#7227 looks similar and is supposedly fixed, but I can still reproduce the problem on a recent RA. I'm not sure who is even doing the config file finding here -- is RA telling rustfmt "use this config file", or is rustfmt supposed to somehow figure this out itself? If the latter, how -- the working directory? AFAIK rustfmt doesn't get the actual filename, it just receives the text on stdin and produces the formatted text on stdout.
rust-analyzer version: rust-analyzer version: 0.3.1641-standalone
rustc version: rustc 1.74.0-nightly (59a829484 2023-08-30)
relevant settings:
The text was updated successfully, but these errors were encountered: