Skip to content

Added support of toolchains for rustfmt #671

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/formatter_options.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ options = {
options = {
-- The default edition of Rust to use when no Cargo.toml file is found
default_edition = "2021",
default_toolchain = "stable"
}
```

Expand Down
4 changes: 3 additions & 1 deletion lua/conform/formatters/rustfmt.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ return {
options = {
-- The default edition of Rust to use when no Cargo.toml file is found
default_edition = "2021",
default_toolchain = "stable",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default_edition is only a default because it's what we use if there is no Cargo.toml file. Let's rename this to just toolchain.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And should add a short comment above to explain it as well

},
args = function(self, ctx)
local args = { "--emit=stdout" }
local toolchain = "+" .. self.options.default_toolchain
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you link me to the documentation for passing +<toolchain> to rustfmt? I've seen this for cargo, but would like to read something about how it works for rustfmt.

local args = { toolchain, "--emit=stdout" }
local edition = util.parse_rust_edition(ctx.dirname) or self.options.default_edition
table.insert(args, "--edition=" .. edition)

Expand Down