From eb7fdc29bb78e3a05fedc3d4a7368b21d7ad9884 Mon Sep 17 00:00:00 2001 From: gered Date: Wed, 11 Sep 2024 13:37:09 -0400 Subject: [PATCH] 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. --- lua/plugins/conform.lua | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/lua/plugins/conform.lua b/lua/plugins/conform.lua index cdb8ae4..4ee38f4 100644 --- a/lua/plugins/conform.lua +++ b/lua/plugins/conform.lua @@ -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' },