nvim: Simplify formatter loading
Since we use Mason to automatically install any formatter we need, there is (currently) no need for the more complicated logic of deciding between multiple formatters (since the one we prefer should always be available). This also fixes an issue that we can set 'prettier' specific options in conform.nvim but those do not apply to 'prettierd' the same way - we now just use prettier and ignore prettierd.
This commit is contained in:
parent
be842ce622
commit
4be3a42ffa
1 changed files with 23 additions and 41 deletions
|
@ -1,49 +1,26 @@
|
|||
---@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
|
||||
local formatters = {
|
||||
angular = { "prettierd", "prettier", stop_after_first = true },
|
||||
astro = { "prettierd", "prettier", stop_after_first = true },
|
||||
angular = { "prettier" },
|
||||
astro = { "prettier" },
|
||||
bash = { "shfmt" },
|
||||
bib = { "bibtex-tidy" },
|
||||
css = function(bufnr)
|
||||
return { first(bufnr, "prettierd", "prettier"), "rustywind" }
|
||||
end,
|
||||
graphql = { "prettierd", "prettier", stop_after_first = true },
|
||||
html = function(bufnr)
|
||||
return { first(bufnr, "prettierd", "prettier"), "rustywind" }
|
||||
end,
|
||||
javascript = { "prettierd", "prettier", stop_after_first = true },
|
||||
javascriptreact = { "prettierd", "prettier", stop_after_first = true },
|
||||
css = { "prettier", "rustywind" },
|
||||
graphql = { "prettier" },
|
||||
html = { "prettier", "rustywind" },
|
||||
javascript = { "prettier" },
|
||||
javascriptreact = { "prettier" },
|
||||
json = { "jq" },
|
||||
liquid = { "prettierd", "prettier", stop_after_first = true },
|
||||
liquid = { "prettier" },
|
||||
lua = { "stylua" },
|
||||
markdown = function(bufnr)
|
||||
return { first(bufnr, "prettierd", "prettier"), "injected" }
|
||||
end,
|
||||
markdown = { "prettier", "injected" },
|
||||
python = { "ruff_fix", "ruff_format", "ruff_organize_imports" },
|
||||
quarto = function(bufnr)
|
||||
return { first(bufnr, "prettierd", "prettier"), "injected" }
|
||||
end,
|
||||
quarto = { "prettier", "injected" },
|
||||
sh = { "shfmt" },
|
||||
sql = { "sleek" },
|
||||
svelte = { "prettierd", "prettier", stop_after_first = true },
|
||||
typescript = { "prettierd", "prettier", stop_after_first = true },
|
||||
typescriptreact = { "prettierd", "prettier", stop_after_first = true },
|
||||
vue = function(bufnr)
|
||||
return { first(bufnr, "prettierd", "prettier"), "rustywind" }
|
||||
end,
|
||||
yaml = { "prettierd", "prettier", stop_after_first = true },
|
||||
svelte = { "prettier" },
|
||||
typescript = { "prettier" },
|
||||
typescriptreact = { "prettier" },
|
||||
vue = { "prettier", "rustywind" },
|
||||
yaml = { "prettier" },
|
||||
zsh = { "shfmt" },
|
||||
}
|
||||
|
||||
|
@ -57,17 +34,22 @@ return {
|
|||
"stevearc/conform.nvim",
|
||||
config = function()
|
||||
require("conform").setup({
|
||||
|
||||
formatters_by_ft = formatters,
|
||||
lsp_format = "fallback",
|
||||
|
||||
format_after_save = function(bufnr)
|
||||
if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then
|
||||
return
|
||||
end
|
||||
return { lsp_fallback = true }
|
||||
end,
|
||||
formatters_by_ft = formatters,
|
||||
})
|
||||
require("conform").formatters.prettier = {
|
||||
options = {
|
||||
ext_parsers = {
|
||||
qmd = "markdown",
|
||||
},
|
||||
},
|
||||
}
|
||||
vim.api.nvim_create_user_command("FormatDisable", function(args)
|
||||
if args.bang then
|
||||
vim.g.disable_autoformat = true
|
||||
|
|
Loading…
Reference in a new issue