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.rs
inrustfmt.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
formatOnSave
using nightlyrustfmt
in one of two ways:Option 1: rust-toolchain
In
rust-toolchain
:nightly
In
.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.rs
in 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
.