Open kgreunke opened 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.
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
This is still an issue...
@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.
After enabling
doom.features.linter.settings.format_on_save
saving a file results in this error:This change fixes the problem while also migrating the autocmd to the nvim lua api and sharing the formatting function with the keybind.