Version of VSCode: 1.28.1
Version of the extension: 0.4.10
OS: GNU/Linux x86_64
I tried to set the following in my workspace settings, but it seems to be ignored. I get different results running "Format Document" in VSCode and cargo +nightly fmt in the command line.
"rust.rustfmt_path": "${env:HOME}/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustfmt"
Is there a way to execute cargo +nightly fmt on format document?
That's tricky - you need to enable unstable_features but that's only allowed for nightly toolchains (here). Until rustfmt_path is stabilised I think you can try and hack it around by setting CFG_RELEASE_CHANNEL env var to nightly when starting VSCode. (Hopefully stuff won't break?)
@wigy-opensource-developer did @Xanewok's suggestion work for you? I've tried without success.
EDIT:
@wigy-opensource-developer
I noticed that ${env:HOME} must be ${env.HOME} to resolve properly. After that it still didn't work though.
As a workaround I've installed https://marketplace.visualstudio.com/items?itemName=emeraldwalk.RunOnSave and configured it as followed:
"emeraldwalk.runonsave": {
"commands": [
{
"match": "\\.rs",
"isAsync": true,
"cmd": "${env.HOME}/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustfmt ${file}",
}
]
},
I'm expecting the rls and runonsave to race against each other, though on a quick test runonsave seems to win the race ;-)
That is a nice workaround, thanks. In the middle of a stressful release I did not want to dig up my VSCode, so I have not even tried the suggestion from @Xanewok, because I was unsure if I will be able to build using stable rustc afterwards.
Just as a note: my workaround causes a side effect of flushing the undo-history in case the file is changed by the configured command.
I believe we can stabilise the rustfmt_path - it's not exactly rocket science and there are not a lot of moving parts where things can go wrong.
@jsgf Have you used the rustfmt_path extensively and if so did you encounter any problems with it so far?
Hi! We haven't been using it. It looks like there's a bug because it passes --file-lines [] if its trying to do a full-file reformat, which ends up being a no-file reformat.
When I try setting rust.rustfmt_path to C:\Users\radix\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\bin\rustfmt.exe (appropriately escaped in the JSON settings file), it doesn't seem to actually change any behavior -- it is still using the stable rustfmt. I know this because the following output shows up when I try to format:
Warning: can't set `fn_single_line = true`, unstable features are only available in nightly channel.
This is solved via a rust-analyzer setting in vscode:
https://github.com/rust-analyzer/rust-analyzer/issues/3627#issuecomment-612021748
(edit) originally from https://github.com/rust-analyzer/rust-analyzer/issues/3916#issuecomment-611617573
Most helpful comment
@wigy-opensource-developer did @Xanewok's suggestion work for you? I've tried without success.
EDIT:
@wigy-opensource-developer
I noticed that
${env:HOME}must be${env.HOME}to resolve properly. After that it still didn't work though.As a workaround I've installed https://marketplace.visualstudio.com/items?itemName=emeraldwalk.RunOnSave and configured it as followed:
I'm expecting the rls and runonsave to race against each other, though on a quick test runonsave seems to win the race ;-)