Can we add delay before formatting "on save" ? #1296
-
I have some conflict using formatters and code actions. But, when I use some code_actions (like whit eslint_d), file is formatted BEFORE the code_action did his job. So code_actions are not working. So my question is : can I add some delay before formatter actually format the file ? like Here's my null-ls config :
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Not sure this is something we'd want to support, since to my knowledge this isn't supported by any actual LSP servers. If all you want is a delay, you should be able to achieve what you want using timers (untested, but it should get you on the right track): local delay = 1000
local format_timer = vim.loop.new_timer()
-- use as vim.api.nvim_create_autocmd callback
local on_insert_leave = function()
format_timer:start(delay, 0, function()
vim.lsp.buf.format() -- add relevant options
end)
end
-- you also probably want to stop the timer on insert re-entry to avoid issues
local on_insert_enter = function()
format_timer:stop()
end |
Beta Was this translation helpful? Give feedback.
Not sure this is something we'd want to support, since to my knowledge this isn't supported by any actual LSP servers. If all you want is a delay, you should be able to achieve what you want using timers (untested, but it should get you on the right track):