ecosse3 / nvim

A non-minimal Neovim config built to work most efficiently with Frontend Development
GNU General Public License v3.0
1.19k stars 109 forks source link

Auto format when saving #175

Open al77ex1 opened 3 months ago

al77ex1 commented 3 months ago

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.

Wakotu commented 1 month ago

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 commented 1 month ago

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