Skip to content

Commit 6d62b2c

Browse files
dam9000ethanellison
authored andcommitted
conform: disable autoformat on save for specified filetypes (nvim-lua#694)
Provide a method to disable autoformat on save lsp fallback for specified filetypes. By default disable for C/C++ as an example, because it does not have a well standardized coding style. Based on conform recipe: https://github.com/stevearc/conform.nvim/blob/master/doc/recipes.md
1 parent 90c3d1f commit 6d62b2c

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

init.lua

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -606,10 +606,16 @@ require('lazy').setup({
606606
'stevearc/conform.nvim',
607607
opts = {
608608
notify_on_error = false,
609-
format_on_save = {
610-
timeout_ms = 500,
611-
lsp_fallback = true,
612-
},
609+
format_on_save = function(bufnr)
610+
-- Disable "format_on_save lsp_fallback" for languages that don't
611+
-- have a well standardized coding style. You can add additional
612+
-- languages here or re-enable it for the disabled ones.
613+
local disable_filetypes = { c = true, cpp = true }
614+
return {
615+
timeout_ms = 500,
616+
lsp_fallback = not disable_filetypes[vim.bo[bufnr].filetype],
617+
}
618+
end,
613619
formatters_by_ft = {
614620
lua = { 'stylua' },
615621
-- Conform can also run multiple formatters sequentially

0 commit comments

Comments
 (0)