fix format_on_save configuration

it actually works properly for selectively enabling/disabling
format on save via conform based on filetype.

i apparently misunderstood how lua tables work and checking if values
exist in them or not.
This commit is contained in:
Gered 2024-09-11 13:37:09 -04:00
parent f3b8664def
commit eb7fdc29bb

View file

@ -16,22 +16,18 @@ return {
opts = { opts = {
notify_on_error = false, notify_on_error = false,
format_on_save = function(bufnr) format_on_save = function(bufnr)
-- Filetypes to apply formatting to on save. Remove from this list local autoformat_filetypes = {
-- to disable formatting on save for that filetype. lua = true,
local filetypes = { rust = true,
'lua',
'rust',
} }
local lsp_format_opt if autoformat_filetypes[vim.bo[bufnr].filetype] then
if filetypes[vim.bo[bufnr].filetype] then return {
lsp_format_opt = 'fallback' timeout_ms = 500,
lsp_format = 'fallback',
}
else else
lsp_format_opt = 'never' return
end end
return {
timeout_ms = 500,
lsp_format = lsp_format_opt,
}
end, end,
formatters_by_ft = { formatters_by_ft = {
lua = { 'stylua' }, lua = { 'stylua' },