-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Format on save in VS Code ignores rustfmt.toml #6973
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
It might. Can you still reproduce this in a non-workspace project? |
So indeed, it works in that case. (I also removed the "workaround" I initially mentioned in the description, it doesn't work - formatting isn't run with it) |
Unfortunately, I have the same problem. My workaround for now, is to use the VSCode extension Run on Save with the following configuration: "emeraldwalk.runonsave": {
"commands": [
{
"match": "\\.rs$",
"cmd": "rustfmt '${file}'"
}
]
} (This needs to be added to a I also have disabled the native VSCode "Format on Save" (otherwise, the |
@Benlitz just to make sure, is that a |
it was on a cargo workspace, but actually it happens as soon as the folder you open in vscode is a folder above the crate folder. I'm joining a simple project. Repro:
And just in case it's a folder separator issue or something similar: I'm having this issue on Windows. I haven't tested it on Linux yet. |
I'm using a Cargo Workspace with a VSCode Workspace that is on the same directory.
I use Linux, so the problem is probably not specific to Windows |
Can we set
|
But what do we set it to? |
To the path of the |
Might be interesting to check what happens if the last part of the config path doesn't exist... Otherwise we could also just chdir as far down as possible to the file path 🤔 |
Looks like it's not as recursive as one would expect:
|
Hallelujah, this will eliminate the need to keep changing my global rustfmt config when changing projects. Thank you for the implementation, this is really useful. |
It still does not seem to work for me. Can someone share their config? |
Same problem here. If I go to the Rust-analyzer option "Rustfmt: Extra Args" and enter But if I create a file |
Happened the same to me, having manually specified it in the vscode extension extra arguments works but the file itself seems to be ignored. |
Uh oh!
There was an error while loading. Please reload this page.
Hi,
It seems that when I save a file in VS Code, it ignores the
rustfmt.toml
file and applies the default configuration for formatting. I just added arustfmt.toml
file with onlymax_width = 160
in it. When I save a file, it clearly applies the default 100 character width. If I runrustfmt [file]
in a console it works properly.Note: I'm working in a workspace with multiple crates in it, and some other crates have their own
rustfmt.toml
. I doubt this is related to the problem but still mentioning.The text was updated successfully, but these errors were encountered: