This repository has been archived by the owner on Aug 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 785
Source specific Configuration
Denis Cornehl edited this page Dec 28, 2021
·
8 revisions
This page documents extended / advanced configurations for specific sources.
The configurations here are user-maintained and not guaranteed to work. If something is broken, fix it! If something is missing, add it!
Note: If you are using
rust-analyzer
, format withrust-analyzer
. It reads edition fromCargo.toml
.
Choose one of the following:
- specify in
rustfmt.toml
.
edition = "2021"
- hardcode it.
null_ls.builtins.formatting.rustfmt.with({
extra_args = { "--edition=2021" }
}
- read from
Cargo.toml
.
null_ls.builtins.formatting.rustfmt.with({
extra_args = function(params)
local cargo_toml = params.root .. "/" .. "Cargo.toml"
local fd = vim.loop.fs_open(cargo_toml, "r", 438)
if not fd then
return
end
local stat = vim.loop.fs_fstat(fd)
local data = vim.loop.fs_read(fd, stat.size, 0)
vim.loop.fs_close(fd)
for _, line in ipairs(vim.split(data, "\n")) do
local edition = line:match([[^edition%s*=%s*%"(%d+)%"]])
if edition then
return { "--edition=" .. edition }
end
end
end
}