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)
|
||||||
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 {
|
return {
|
||||||
"stevearc/conform.nvim",
|
"stevearc/conform.nvim",
|
||||||
opts = {
|
opts = {
|
||||||
-- https://github.com/stevearc/conform.nvim?tab=readme-ov-file#setup
|
-- https://github.com/stevearc/conform.nvim?tab=readme-ov-file#setup
|
||||||
notify_on_error = true,
|
notify_on_error = true,
|
||||||
formatters = {
|
formatters = {
|
||||||
v_fmt = {
|
-- v_fmt = {
|
||||||
command = "v",
|
-- command = "v",
|
||||||
args = { "fmt" },
|
-- args = { "fmt" },
|
||||||
},
|
-- },
|
||||||
},
|
},
|
||||||
-- Note that all these need to be available at runtime, add them to flake.nix#runtimeDependencies
|
-- Note that all these need to be available at runtime, add them to flake.nix#runtimeDependencies
|
||||||
formatters_by_ft = {
|
formatters_by_ft = {
|
||||||
lua = { "stylua" },
|
lua = { "stylua" },
|
||||||
nix = { "nixfmt" },
|
nix = { "nixfmt" },
|
||||||
vlang = { "v_fmt" },
|
-- vlang = { "v_fmt" },
|
||||||
typescript = { { "prettierd", "prettier" }, "rustywind" },
|
typescript = expandFormatters({ { "prettierd", "prettier" }, "rustywind" }),
|
||||||
typescriptreact = { { "prettierd", "prettier" }, "rustywind" },
|
typescriptreact = expandFormatters({ { "prettierd", "prettier" }, "rustywind" }),
|
||||||
javascript = { { "prettierd", "prettier" }, "rustywind" },
|
javascript = expandFormatters({ { "prettierd", "prettier" }, "rustywind" }),
|
||||||
javascriptreact = { { "prettierd", "prettier" }, "rustywind" },
|
javascriptreact = expandFormatters({ { "prettierd", "prettier" }, "rustywind" }),
|
||||||
|
|
||||||
-- TODO revisit these I'd like to use them but they are not in nixpkgs yet
|
-- TODO revisit these I'd like to use them but they are not in nixpkgs yet
|
||||||
-- https://nixos.org/guides/nix-pills/
|
-- https://nixos.org/guides/nix-pills/
|
||||||
-- markdown = { "mdslw", "mdsf"},
|
-- markdown = { "mdslw", "mdsf"},
|
||||||
markdown = { "markdownlint-cli2" },
|
markdown = { "markdownlint-cli2" },
|
||||||
-- rust = { "rustfmt" },
|
-- rust = { "rustfmt" },
|
||||||
|
|
||||||
|
["*"] = { lsp_format = "fallback" },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
keys = {
|
keys = {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue