aboutsummaryrefslogtreecommitdiffstats
path: root/lua/conform/formatters/rustfmt.lua
diff options
context:
space:
mode:
authorSteven Arcangeli <506791+stevearc@users.noreply.github.com>2024-03-13 08:43:23 -0700
committerGitHub <noreply@github.com>2024-03-13 08:43:23 -0700
commit0ff1b7d32fd3e8df194ca5ebec1dab9c61fb9911 (patch)
tree8cb5057734a5700dee5e0dc920ed73d55524d4db /lua/conform/formatters/rustfmt.lua
parentdb2c697fe8302f0328b50b480204be1b577a1e2f (diff)
fix(rustfmt): use Cargo.toml settings and default to recent edition (#328)
Diffstat (limited to 'lua/conform/formatters/rustfmt.lua')
-rw-r--r--lua/conform/formatters/rustfmt.lua15
1 files changed, 14 insertions, 1 deletions
diff --git a/lua/conform/formatters/rustfmt.lua b/lua/conform/formatters/rustfmt.lua
index d8f0f19..34fb09b 100644
--- a/lua/conform/formatters/rustfmt.lua
+++ b/lua/conform/formatters/rustfmt.lua
@@ -5,5 +5,18 @@ return {
description = "A tool for formatting rust code according to style guidelines.",
},
command = "rustfmt",
- args = { "--emit=stdout" },
+ options = {
+ -- The default edition of Rust to use when no Cargo.toml file is found
+ default_edition = "2021",
+ },
+ args = function(self, ctx)
+ local args = { "--emit=stdout" }
+ local manifest = vim.fs.find("Cargo.toml", { upward = true, path = ctx.dirname })[1]
+ if manifest then
+ table.insert(args, "--manifest-path=" .. manifest)
+ elseif self.options.default_edition then
+ table.insert(args, "--edition=" .. self.options.default_edition)
+ end
+ return args
+ end,
}