diff --git a/nvim/dot-config/nvim/lua/plugins/conform.lua b/nvim/dot-config/nvim/lua/plugins/conform.lua index 659236c..c289a86 100644 --- a/nvim/dot-config/nvim/lua/plugins/conform.lua +++ b/nvim/dot-config/nvim/lua/plugins/conform.lua @@ -1,4 +1,5 @@ -- https://github.com/stevearc/conform.nvim +local slow_format_filetypes = {} return { "stevearc/conform.nvim", event = { "BufWritePre" }, @@ -35,10 +36,27 @@ return { -- ["*"] = { "codespell" }, ["_"] = { "trim_whitespace", "trim_newlines" }, }, + format_on_save = function(bufnr) + if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then + return + end + if slow_format_filetypes[vim.bo[bufnr].filetype] then + return + end + local function on_format(err) + if err and err:match("timeout$") then + slow_format_filetypes[vim.bo[bufnr].filetype] = true + end + end + return { timeout_ms = 200, lsp_fallback = true }, on_format + end, format_after_save = function(bufnr) if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then return end + if not slow_format_filetypes[vim.bo[bufnr].filetype] then + return + end return { lsp_fallback = true } end, notify_on_error = true,