Delay when formatting files on save #485
-
Hi all, I'm in the process of moving my configuration for neovim to lua. I'm setting up null-ls for formatting via eslint_d and prettier (as these are needed for my fulltime job) and i'm noticing a delay when I save a file. Before this I used to use coc-eslint and coc-prettier, and never noticed any delay when saving a file. The lag is bad in typescript files, but even worse in jsx/tsx. Even for one line changes, it can take up to a second to actually format. This is my first time setting stuff up in lua, so maybe i'm doing something wrong? Here is my local null_lus_status_ok, null_ls = pcall(require, 'null-ls')
if not null_lus_status_ok then
return
end
local formatting = null_ls.builtins.formatting
local diagnostics = null_ls.builtins.diagnostics
null_ls.setup({
debug = false,
sources = {
formatting.black.with({ extra_args = {'--fast'} }),
formatting.prettier,
formatting.eslint_d
},
on_attach = function(client)
if client.resolved_capabilities.document_formatting then
vim.cmd("autocmd BufWritePre <buffer> lua vim.lsp.buf.formatting()")
end
end,
}) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 16 replies
-
Same is happening with me - any updates would be hugely appreciated. |
Beta Was this translation helpful? Give feedback.
-
You have format on save which is causing the lag. For me I don't think you can make it instant and have format/lint on save. The best bet would be to remove the auto command and call the formatting manually with a keymap. |
Beta Was this translation helpful? Give feedback.
You have format on save which is causing the lag.
For me
eslint_d
takes a second or two most of the time to chew up the buffer. Plus I'm pretty sure you are running botheslint_d
andprettier
on save since they both format/lintjs
/ts
/jsx
/tsx
.I don't think you can make it instant and have format/lint on save.
The best bet would be to remove the auto command and call the formatting manually with a keymap.