Switch to async formatting automatically if the formatter is slow
This commit is contained in:
parent
228cd34087
commit
cf6ffdb83a
|
@ -1,4 +1,5 @@
|
||||||
-- https://github.com/stevearc/conform.nvim
|
-- https://github.com/stevearc/conform.nvim
|
||||||
|
local slow_format_filetypes = {}
|
||||||
return {
|
return {
|
||||||
"stevearc/conform.nvim",
|
"stevearc/conform.nvim",
|
||||||
event = { "BufWritePre" },
|
event = { "BufWritePre" },
|
||||||
|
@ -35,10 +36,27 @@ return {
|
||||||
-- ["*"] = { "codespell" },
|
-- ["*"] = { "codespell" },
|
||||||
["_"] = { "trim_whitespace", "trim_newlines" },
|
["_"] = { "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)
|
format_after_save = function(bufnr)
|
||||||
if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then
|
if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
if not slow_format_filetypes[vim.bo[bufnr].filetype] then
|
||||||
|
return
|
||||||
|
end
|
||||||
return { lsp_fallback = true }
|
return { lsp_fallback = true }
|
||||||
end,
|
end,
|
||||||
notify_on_error = true,
|
notify_on_error = true,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user