aboutsummaryrefslogtreecommitdiffstats
path: root/lua/conform/util.lua
diff options
context:
space:
mode:
authorMads Hougesen <mads@mhouge.dk>2024-05-13 19:23:40 +0200
committerGitHub <noreply@github.com>2024-05-13 11:23:40 -0600
commitb52d462cb7bea5e81174ece43eb349357add2f11 (patch)
tree4e0b9e91d6503846d3d8b7c6edbc517740e370f1 /lua/conform/util.lua
parent40faaa8fdd0b7f98f58070943306fd93abb5caad (diff)
feat: add support for yew-fmt (#398)
* feat: add support for yew-fmt Should close #314 :) * refactor: copy rustfmt to yew-fmt * fix: use correct default_edition * refactor: extract Cargo.toml parsing into utility function * refactor: yew-fmt doesn't rely directly on rustfmt definition --------- Co-authored-by: Steven Arcangeli <stevearc@stevearc.com>
Diffstat (limited to 'lua/conform/util.lua')
-rw-r--r--lua/conform/util.lua17
1 files changed, 17 insertions, 0 deletions
diff --git a/lua/conform/util.lua b/lua/conform/util.lua
index 2f334d0..fe2a306 100644
--- a/lua/conform/util.lua
+++ b/lua/conform/util.lua
@@ -187,4 +187,21 @@ M.buf_get_changedtick = function(bufnr)
end
end
+---Parse the rust edition from the Cargo.toml file
+---@param dir string
+---@return string?
+M.parse_rust_edition = function(dir)
+ local manifest = vim.fs.find("Cargo.toml", { upward = true, path = dir })[1]
+ if manifest then
+ for line in io.lines(manifest) do
+ if line:match("^edition *=") then
+ local edition = line:match("%d+")
+ if edition then
+ return edition
+ end
+ end
+ end
+ end
+end
+
return M