muturgan
muturgan

Reputation: 505

How to apply a style_edition option for rustfmt on a file saving in vscode?

I have a .vscode/settings.json file:

{
  "[rust]": {
    "editor.inlayHints.enabled": "offUnlessPressed",
    "editor.defaultFormatter": "rust-lang.rust-analyzer",
    "editor.formatOnSave": true
  }
}

So I enjoy rs files autoformatting on save. But as I can see it runs a cargo fmt command.
I have added a style_edition = "2024" line to my rustfmt.toml. And now if I run a cargo +nightly fmt -- --check command then I get some formatting error messages.

How to force a vscode to check my rustfmt.toml file and apply a +nightly option on a formatOnSave action?

Upvotes: 0

Views: 87

Answers (1)

muturgan
muturgan

Reputation: 505

I have added an extra option rust-analyzer.rustfmt.extraArgs to my settings.json file:

{
  "[rust]": {
    "editor.inlayHints.enabled": "offUnlessPressed",
    "editor.defaultFormatter": "rust-lang.rust-analyzer",
    "editor.formatOnSave": true
  },
  "rust-analyzer.rustfmt.extraArgs": ["+nightly"]
}

Now it works as I expect it - file saving applies formatting according with style_edition, imports_granularity, group_imports and other nightly options from a rustfmt.toml.

Upvotes: 0

Related Questions