make formatting config work again
This commit is contained in:
parent
ca328ee3a1
commit
5ce78f6a69
1 changed files with 44 additions and 9 deletions
|
@ -15,32 +15,67 @@ local function formatCurrent(retry)
|
|||
end)
|
||||
end
|
||||
|
||||
---@param bufnr integer
|
||||
---@param ... string
|
||||
---@return string
|
||||
local function first(bufnr, ...)
|
||||
local conform = require("conform")
|
||||
for i = 1, select("#", ...) do
|
||||
local formatter = select(i, ...)
|
||||
if conform.get_formatter_info(formatter, bufnr).available then
|
||||
return formatter
|
||||
end
|
||||
end
|
||||
return select(1, ...)
|
||||
end
|
||||
|
||||
-- Make function that converts { { "prettierd", "prettier" }, "rustywind" } to
|
||||
--function (bufnr)
|
||||
-- return { first(bufnr, "prettierd", "prettier"), "rustywind" }
|
||||
-- end,
|
||||
local function expandFormatters(formatters)
|
||||
return function(bufnr)
|
||||
local result = {}
|
||||
for i = 1, #formatters do
|
||||
local formatter = formatters[i]
|
||||
if type(formatter) == "table" then
|
||||
result[i] = first(bufnr, unpack(formatter))
|
||||
else
|
||||
result[i] = formatter
|
||||
end
|
||||
end
|
||||
return result
|
||||
end
|
||||
end
|
||||
|
||||
return {
|
||||
"stevearc/conform.nvim",
|
||||
opts = {
|
||||
-- https://github.com/stevearc/conform.nvim?tab=readme-ov-file#setup
|
||||
notify_on_error = true,
|
||||
formatters = {
|
||||
v_fmt = {
|
||||
command = "v",
|
||||
args = { "fmt" },
|
||||
},
|
||||
-- v_fmt = {
|
||||
-- command = "v",
|
||||
-- args = { "fmt" },
|
||||
-- },
|
||||
},
|
||||
-- Note that all these need to be available at runtime, add them to flake.nix#runtimeDependencies
|
||||
formatters_by_ft = {
|
||||
lua = { "stylua" },
|
||||
nix = { "nixfmt" },
|
||||
vlang = { "v_fmt" },
|
||||
typescript = { { "prettierd", "prettier" }, "rustywind" },
|
||||
typescriptreact = { { "prettierd", "prettier" }, "rustywind" },
|
||||
javascript = { { "prettierd", "prettier" }, "rustywind" },
|
||||
javascriptreact = { { "prettierd", "prettier" }, "rustywind" },
|
||||
-- vlang = { "v_fmt" },
|
||||
typescript = expandFormatters({ { "prettierd", "prettier" }, "rustywind" }),
|
||||
typescriptreact = expandFormatters({ { "prettierd", "prettier" }, "rustywind" }),
|
||||
javascript = expandFormatters({ { "prettierd", "prettier" }, "rustywind" }),
|
||||
javascriptreact = expandFormatters({ { "prettierd", "prettier" }, "rustywind" }),
|
||||
|
||||
-- TODO revisit these I'd like to use them but they are not in nixpkgs yet
|
||||
-- https://nixos.org/guides/nix-pills/
|
||||
-- markdown = { "mdslw", "mdsf"},
|
||||
markdown = { "markdownlint-cli2" },
|
||||
-- rust = { "rustfmt" },
|
||||
|
||||
["*"] = { lsp_format = "fallback" },
|
||||
},
|
||||
},
|
||||
keys = {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue