restrict conform.nvim format on save to only specific filetypes
This commit is contained in:
parent
8f912a52df
commit
e4d067b26d
2 changed files with 23 additions and 39 deletions
|
|
@ -4,16 +4,29 @@ return {
|
|||
formatters_by_ft = {
|
||||
javascript = { "prettierd", "prettier", stop_after_first = true },
|
||||
kulala = { "kulala-fmt" },
|
||||
lua = { lsp_format = "fallback" },
|
||||
go = { lsp_format = "fallback" },
|
||||
rust = { lsp_format = "fallback" },
|
||||
toml = { lsp_format = "fallback" },
|
||||
yaml = { lsp_format = "fallback" },
|
||||
java = { lsp_format = "fallback" }
|
||||
},
|
||||
format_on_save = {
|
||||
timeout_ms = 500,
|
||||
lsp_format = "fallback",
|
||||
},
|
||||
},
|
||||
init = function()
|
||||
local FILETYPES_TO_FORMAT_ON_SAVE = {
|
||||
"javascript", "javascriptreact", "typescript", "typescriptreact",
|
||||
"kulala", "lua", "go", "rust", "toml", "json", "yaml", "java" }
|
||||
|
||||
vim.api.nvim_create_autocmd("BufWritePre", {
|
||||
pattern = "*",
|
||||
callback = function(args)
|
||||
local ft = vim.bo[args.buf].filetype
|
||||
|
||||
for _, t in ipairs(FILETYPES_TO_FORMAT_ON_SAVE) do
|
||||
if ft == t then
|
||||
require("conform").format({
|
||||
bufnr = args.buf,
|
||||
timeout_ms = 500,
|
||||
lsp_format = "fallback",
|
||||
})
|
||||
return
|
||||
end
|
||||
end
|
||||
end,
|
||||
})
|
||||
end
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue