rust-analyzer: Format on auto-saving doesn't work
I have formatOnSave enabled and autoSave set. Yet automatic saving does not seem to trigger formatting as manual saving does. Is this a rust-analyzer issue?
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 9
- Comments: 19 (8 by maintainers)
Perhaps
"editor.formatOnSaveMode": "modificationsIfAvailable"or"editor.formatOnSaveMode": "modifications"has a conflict with auto-format ofrust-analyzer. Setting it tofileon rust specified settings solved this problem for me.Maybe it should be this:
with
all of which go in
settings.jsonHad the same problem, had
"editor.formatOnSave": true,and"files.autoSave": "afterDelay",but files did not get formatted.I looked into my
settings.jsonand found thisand removing this fixed the auto-formatting for me 😃
I just really started getting into rust, so excuse my ignorance. Same for vscode plugins.
I ran into
rustfmtjust a few min ago. It’s installed withrustup component add rustfmt.Usage is
rustfmt [options] <file>.For me it was this setting that made it work:
That one will definitively not work. Only nightly rustfmt supports range formatting and rust-analyzer doesn’t implement support for using this mode.
There seem to be working workarounds here and as this i a client issue in the first place I’ll go ahead and close this
This wasn’t working for me. After going through my settings, I found
"editor.formatOnSaveMode": "modifications",I changed it to
"editor.formatOnSaveMode": "file",And everything started workingCan definitely confirm the other comment about this solution
@pinkponk when this happens, try
cargo fmt. If it doesn’t work, it’s arustfmtbug.No, this is still not working for me. I have
formatOnSaveset totrue,files.autoSaveset toafterDelay(300ms) but files are not getting formatted automatically. I don’t have thedefaultFormatterconfig that Matthias found.