Stream: t-compiler/rust-analyzer

Topic: Running rustfmt 2 in Rust-Analyzer


Dirkjan Ochtman (Feb 17 2021 at 08:59, on Zulip):

The author of one of the projects I work on insists on using rustfmt 2 (that is, rustfmt + cargo-fmt compiled with CFG_RELEASE=nightly and CFG_RELEASE_CHANNEL=nightly -- this is actually different from running cargo +nightly fmt in my understanding)

Dirkjan Ochtman (Feb 17 2021 at 09:00, on Zulip):

Now I have that rustfmt installed in and can basically run it as PATH=~/src/rustls/target/rustfmt/bin:$PATH ./target/rustfmt/bin/cargo-fmt, but I was wondering if I can somehow get RA to run that for me, via the rustfmt.overrideCommand

Dirkjan Ochtman (Feb 17 2021 at 09:01, on Zulip):

So I'm wondering, is there any way to set the path similar to this? (I think that's necessary because it's how cargo-fmt finds rustfmt)

matklad (Feb 17 2021 at 09:01, on Zulip):

the path is to trick cargo-fmt to pick the right one?

matklad (Feb 17 2021 at 09:02, on Zulip):

try rust-analyzer.server.env

matklad (Feb 17 2021 at 09:02, on Zulip):

does cargo fmt honor RUSTFMT env var?

matklad (Feb 17 2021 at 09:03, on Zulip):

wait, we don't actually call cargo fmt ourselves, we run rustfmt directly. So just rustmft.command should help

matklad (Feb 17 2021 at 09:04, on Zulip):

(you probably want the simpler version, without override. We need better names here)

Dirkjan Ochtman (Feb 17 2021 at 09:04, on Zulip):

ah, so I just put the path to my rustfmt in overrideCommand?

Dirkjan Ochtman (Feb 17 2021 at 09:04, on Zulip):

ok

Dirkjan Ochtman (Feb 17 2021 at 09:04, on Zulip):

this is what I found when searching the settings

Dirkjan Ochtman (Feb 17 2021 at 09:05, on Zulip):

when I search for rustfmt in the VS Code settings, I only find Rustfmt: Extra Args and Rustfmt: Override Command

matklad (Feb 17 2021 at 09:06, on Zulip):

urgh, yeah, I am imagining things

Dirkjan Ochtman (Feb 17 2021 at 09:06, on Zulip):

yay, it works

Dirkjan Ochtman (Feb 17 2021 at 09:06, on Zulip):

awesome

Dirkjan Ochtman (Feb 17 2021 at 09:07, on Zulip):

thanks

matklad (Feb 17 2021 at 09:07, on Zulip):

so, yeah, you need overrideCommand (or you can also send a PR implementing rust-analyzer.cargo.bin and rust-analyzer.rustfmt.bin)

Dirkjan Ochtman (Feb 17 2021 at 09:10, on Zulip):

I don't really want to override cargo bin, only specifically the rustfmt stuff

Dirkjan Ochtman (Feb 17 2021 at 09:10, on Zulip):

but anyway, I'm happy now :)

Last update: Jul 28 2021 at 03:15UTC