doom-neovim / doom-nvim

A Neovim configuration for the advanced martian hacker
GNU General Public License v2.0
1.01k stars 107 forks source link

Fix linter format on save autocmd #402

Open kgreunke opened 2 years ago

kgreunke commented 2 years ago

After enabling doom.features.linter.settings.format_on_save saving a file results in this error:

Error detected while processing BufWritePre Autocommands for "<buffer=4>":
E5107: Error loading lua [string ":lua"]:1: unexpected symbol near '=='

This change fixes the problem while also migrating the autocmd to the nvim lua api and sharing the formatting function with the keybind.

kgreunke commented 2 years ago

I realize this is probably not the best lua as this is the first time I've really messed with it. Please give me some suggestions as to how this might be done better. I tried to make the callback function a local function at the beginning of the file. That worked for the keybind, but wouldn't work for the autocmd. This was the best thing I could come up with that worked for both.

I also think that I may have broken something else with the Lsp servers. While the autoformat works, it asks you to select a language server every time you save (at least for lua files). Not sure why.

connorgmeehan commented 2 years ago

Hey @kgreunke thanks for the PR and good catch! To be honest the lua looks good to me, the one change is that we'd like to keep 0.7 support around for a while longer. Could you re-add the old autocommand and use a check to see if nvim is 0.8 to use the lua version. Also add a little TODO: comment so it's easy to find the old code for when we remove 0.7 support.

if vim.fn.has("nvim-0.8") then
  -- your code that uses `nvim_create_autocmd`.
else
        -- TODO: Remove this nvim-0.7 compatibility next release.
        vim.cmd([[
        augroup LspFormatting
          autocmd! * <buffer>
          autocmd BufWritePre <buffer> lua doom.modules.features.linter.utils.format_buffer()
        augroup END
        ]])
end
robclancy commented 1 year ago

This is still an issue...

kgreunke commented 1 year ago

@robclancy I gave up on nvim as a "production" editor shortly after I tried to fix this problem. The project is welcome to this code as is or as a basis for a fix, but I won't be doing any more work on it.