2024-10-10 00:48:10 -07:00
|
|
|
return {
|
|
|
|
"conform.nvim",
|
|
|
|
event = "BufWritePre",
|
|
|
|
cmd = "ConformInfo",
|
2024-10-10 13:23:08 -07:00
|
|
|
keys = {
|
|
|
|
{
|
|
|
|
"<leader>cf",
|
|
|
|
function()
|
|
|
|
require("conform").format({ async = true })
|
|
|
|
end,
|
|
|
|
desc = "Format code",
|
|
|
|
mode = { "n", "v" },
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"<leader>ctf",
|
|
|
|
function()
|
|
|
|
if vim.g.disable_autoformat then
|
|
|
|
vim.g.disable_autoformat = false
|
|
|
|
else
|
|
|
|
vim.g.disable_autoformat = true
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
desc = "Disable autoformat on save globally",
|
|
|
|
mode = { "n", "v" },
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"<leader>cbf",
|
|
|
|
function()
|
|
|
|
if vim.b[0].disable_autoformat then
|
|
|
|
vim.b[0].disable_autoformat = false
|
|
|
|
else
|
|
|
|
vim.b[0].disable_autoformat = true
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
desc = "Disable autoformat on save buffer",
|
|
|
|
mode = { "n", "v" },
|
|
|
|
},
|
|
|
|
},
|
2024-10-10 00:48:10 -07:00
|
|
|
after = function()
|
|
|
|
require("conform").setup({
|
|
|
|
format_on_save = function(bufnr)
|
|
|
|
if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
return { timeout_ms = 500, lsp_fallback = true }
|
|
|
|
end,
|
|
|
|
default_format_opts = {
|
|
|
|
lsp_format = "fallback",
|
|
|
|
},
|
|
|
|
formatters_by_ft = {
|
|
|
|
lua = { "stylua" },
|
|
|
|
python = { "black" },
|
|
|
|
rust = { "rustfmt" },
|
|
|
|
javascript = { "prettierd", "prettier", stop_after_first = true },
|
|
|
|
typescript = { "prettierd", "prettier", stop_after_first = true },
|
|
|
|
nix = { "nixfmt" },
|
|
|
|
haskell = { "fourmolu", "ormolu", stop_after_first = true },
|
|
|
|
json = { "prettierd", "prettier", stop_after_first = true },
|
|
|
|
toml = { "taplo", stop_after_first = true },
|
|
|
|
yaml = { "prettierd", "prettier", stop_after_first = true },
|
|
|
|
typst = { "typstyle" },
|
2024-10-17 00:59:39 -07:00
|
|
|
tsx = { "prettier" },
|
|
|
|
svelte = { "prettier" },
|
2024-10-10 00:48:10 -07:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
vim.o.formatexpr = "v:lua.require'conform'.formatexpr()"
|
|
|
|
end,
|
|
|
|
}
|