default to not format on save, except for explicitly listed filetypes

This commit is contained in:
Gered 2024-09-06 18:36:15 -04:00
parent bd7eb9be0f
commit bc0cf8961e

View file

@ -16,15 +16,17 @@ return {
opts = {
notify_on_error = false,
format_on_save = function(bufnr)
-- Disable "format_on_save lsp_fallback" for languages that don't
-- have a well standardized coding style. You can add additional
-- languages here or re-enable it for the disabled ones.
local disable_filetypes = { c = true, cpp = true }
-- Filetypes to apply formatting to on save. Remove from this list
-- to disable formatting on save for that filetype.
local filetypes = {
'lua',
'rust',
}
local lsp_format_opt
if disable_filetypes[vim.bo[bufnr].filetype] then
lsp_format_opt = 'never'
else
if filetypes[vim.bo[bufnr].filetype] then
lsp_format_opt = 'fallback'
else
lsp_format_opt = 'never'
end
return {
timeout_ms = 500,