54 lines
1.4 KiB
Lua
54 lines
1.4 KiB
Lua
return {
|
|
{ -- Autoformat
|
|
'stevearc/conform.nvim',
|
|
event = { 'BufWritePre' },
|
|
cmd = { 'ConformInfo' },
|
|
keys = {
|
|
{
|
|
'<leader>f',
|
|
function()
|
|
require('conform').format { async = true, lsp_format = 'fallback' }
|
|
end,
|
|
mode = '',
|
|
desc = '[F]ormat buffer',
|
|
},
|
|
},
|
|
opts = {
|
|
notify_on_error = false,
|
|
format_on_save = function(bufnr)
|
|
local autoformat_filetypes = {
|
|
lua = true,
|
|
rust = true,
|
|
}
|
|
if autoformat_filetypes[vim.bo[bufnr].filetype] then
|
|
return {
|
|
timeout_ms = 500,
|
|
lsp_format = 'fallback',
|
|
}
|
|
else
|
|
return
|
|
end
|
|
end,
|
|
formatters_by_ft = {
|
|
lua = { 'stylua' },
|
|
yaml = { 'yamlfmt' },
|
|
c = { 'clang-format' },
|
|
},
|
|
formatters = {
|
|
['yamlfmt'] = {
|
|
prepend_args = { '-formatter', 'retain_line_breaks_single=true,trim_trailing_whitespace=true' },
|
|
},
|
|
-- all of the builtin clang-format styles are pretty bad IMHO. don't fallback to any.
|
|
-- unfortunately, `--fallback-style` doesn't allow inline customization like the
|
|
-- `--style` option does.
|
|
-- i really can't say that i'm impressed with clang-format overall ...
|
|
['clang-format'] = {
|
|
prepend_args = { '--style=file', '--fallback-style=none' },
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
-- vim: ts=2 sts=2 sw=2 et
|