rust-lang / rust-lang/rust-analyzer
`formatOnSave` with VSCode extension does not respect `ignore` config in rustfmt.toml
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
Ran into this while working in the rustc repo. There are a number of paths in rustfmt.toml that are ignored, but if you open and then save any of them, then the rust-analyzer VSCode extension still formats the contents with rustfmt.
Minimal steps to reproduce
-
Create empty project with
cargo new. -
Write some poorly formatted code to
src/main.rs:fn main () { println!("Hello, world!"); } -
Ignore
src/main.rsinrustfmt.toml:ignore = [ "src/main.rs", ] -
Demonstrate that nightly rustfmt respects this configuration:
$ cargo +nightly fmt -- src/main.rs $ cat src/main.rs fn main () { println!("Hello, world!"); } -
Enable
formatOnSaveusing nightlyrustfmtin one of two ways:Option 1: rust-toolchain
In
rust-toolchain:nightlyIn
.vscode/settings.json:{ "editor.formatOnSave": true }Option 2: overrideCommand
In
.vscode/settings.json:{ "rust-analyzer.rustfmt.overrideCommand": [ "/YOUR/HOME/.rustup/toolchains/nightly-YOUR-HOST-TRIPLE/bin/rustfmt" ], "editor.formatOnSave": true } -
Open
src/main.rsin VSCode and save.
Observed Behavior
The rust-analyzer extension formats the code in src/main.rs.
Expected behavior
The rust-analyzer extension respects the configuration in rustfmt.toml and
does not format the code in src/main.rs.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the rust-analyzer VSCode extension's formatOnSave path and compare its rustfmt invocation with cargo +nightly fmt using the rustfmt.toml ignore setting. Reproduce with .vscode/settings.json and the ignored src/main.rs example. Done means saving the ignored file leaves it unchanged, with coverage for the configuration and format-on-save behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust, vscode
- Domain
- developer-experience, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100