nvim icon indicating copy to clipboard operation
nvim copied to clipboard

Auto format when saving

Open al77ex1 opened this issue 1 year ago • 2 comments

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.

al77ex1 avatar Mar 27 '24 08:03 al77ex1

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.

Wakotu avatar May 24 '24 13:05 Wakotu

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>.

Wakotu avatar May 24 '24 13:05 Wakotu

It's fixed in v4.0.0.

ecosse3 avatar Sep 07 '24 08:09 ecosse3