Reorder rust formatters (rustfmt primary), switch python from isort/black to ruff/dprint, and enable format_on_save with lsp_fallback.
44 lines
1.4 KiB
Lua
44 lines
1.4 KiB
Lua
vim.pack.add({
|
|
{ src = 'https://github.com/stevearc/conform.nvim' },
|
|
})
|
|
|
|
local conform = require('conform')
|
|
|
|
conform.setup({
|
|
notify_on_error = false,
|
|
formatters = {
|
|
shfmt = {
|
|
prepend_args = { "-i", "2", "-ci" },
|
|
},
|
|
dprint = {
|
|
condition = function(ctx)
|
|
return vim.fs.find({ "dprint.json" }, { path = ctx.filename, upward = true })[1]
|
|
end,
|
|
},
|
|
},
|
|
formatters_by_ft = {
|
|
c = { "clang_format" },
|
|
cpp = { "clang_format" },
|
|
lua = { 'stylua' },
|
|
go = { "goimports", "gofmt" },
|
|
rust = { "rustfmt", "dprint", lsp_format = "fallback" },
|
|
python = { "ruff", "dprint", stop_after_first = true },
|
|
javascript = { "dprint", "prettier", stop_after_first = true },
|
|
markdown = { "dprint", "prettier", stop_after_first = true },
|
|
javascriptreact = { "dprint", "prettier", stop_after_first = true },
|
|
typescript = { "dprint", "prettier", stop_after_first = true },
|
|
typescriptreact = { "dprint", "prettier", stop_after_first = true },
|
|
svelte = { "dprint", "prettier", stop_after_first = true },
|
|
html = { "dprint", "prettier", stop_after_first = true },
|
|
},
|
|
format_on_save = {
|
|
lsp_fallback = true,
|
|
},
|
|
})
|
|
|
|
vim.keymap.set({ 'n', 'v' }, '<leader>bf',
|
|
function()
|
|
conform.format { async = true }
|
|
end,
|
|
{ desc = 'Format buffer' })
|