conform: autoformat on save only for specified filetypes

Enable the autoformat on save only for specified filetypes.
By default this is only for lua, similar as LSP is by default
only enabled for lua. Based on conform recipe:
https://github.com/stevearc/conform.nvim/blob/master/doc/recipes.md
This commit is contained in:
Damjan 9000 2024-03-04 22:45:44 +01:00
parent b83b2b061c
commit dca3a7f8b9

View file

@ -607,10 +607,16 @@ require('lazy').setup {
'stevearc/conform.nvim', 'stevearc/conform.nvim',
opts = { opts = {
notify_on_error = false, notify_on_error = false,
format_on_save = { format_on_save = function(bufnr)
-- Enable format on save for specified filetypes
local enable_filetypes = { 'lua' }
if vim.tbl_contains(enable_filetypes, vim.bo[bufnr].filetype) then
return {
timeout_ms = 500, timeout_ms = 500,
lsp_fallback = true, lsp_fallback = true,
}, }
end
end,
formatters_by_ft = { formatters_by_ft = {
lua = { 'stylua' }, lua = { 'stylua' },
-- Conform can also run multiple formatters sequentially -- Conform can also run multiple formatters sequentially