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:
parent
f3b8664def
commit
eb7fdc29bb
|
@ -16,22 +16,18 @@ return {
|
|||
opts = {
|
||||
notify_on_error = false,
|
||||
format_on_save = function(bufnr)
|
||||
-- Filetypes to apply formatting to on save. Remove from this list
|
||||
-- to disable formatting on save for that filetype.
|
||||
local filetypes = {
|
||||
'lua',
|
||||
'rust',
|
||||
local autoformat_filetypes = {
|
||||
lua = true,
|
||||
rust = true,
|
||||
}
|
||||
local lsp_format_opt
|
||||
if filetypes[vim.bo[bufnr].filetype] then
|
||||
lsp_format_opt = 'fallback'
|
||||
if autoformat_filetypes[vim.bo[bufnr].filetype] then
|
||||
return {
|
||||
timeout_ms = 500,
|
||||
lsp_format = 'fallback',
|
||||
}
|
||||
else
|
||||
lsp_format_opt = 'never'
|
||||
return
|
||||
end
|
||||
return {
|
||||
timeout_ms = 500,
|
||||
lsp_format = lsp_format_opt,
|
||||
}
|
||||
end,
|
||||
formatters_by_ft = {
|
||||
lua = { 'stylua' },
|
||||
|
|
Loading…
Reference in a new issue