nvim
nvim copied to clipboard
Auto format when saving
I'm in the React component file (.tsx) and turning on auto format when saving (<leader> + c + t). And an error message appears:
E5108: Error executing lua /home/alex/.config/nvim/lua/config/lsp/functions.lua:28: Required: 'command' or 'callback'
stack traceback:
[C]: in function 'nvim_create_autocmd'
/home/alex/.config/nvim/lua/config/lsp/functions.lua:28: in function 'enable_format_on_save'
/home/alex/.config/nvim/lua/config/lsp/functions.lua:42: in function 'toggle_format_on_save'
[string ":lua"]:1: in main chunk
just formatting the code (<leader> + c + f) works.
It's a bug in lua/config/lsp/functions.lua:29.
original code:
callback = M.format(),
should be modified to
callback = M.format,
i.e. removing the trailing parenthesis.
However, I found that once the format_on_save mode turned on, the current buffer would keep in an unsaved state even after you hit <C-s>.
It's fixed in v4.0.0.