Skip to content
This repository has been archived by the owner on Apr 16, 2024. It is now read-only.

Fix linter format on save autocmd #402

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kgreunke
Copy link

@kgreunke kgreunke commented Oct 9, 2022

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
Copy link
Author

kgreunke commented Oct 9, 2022

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
Copy link
Collaborator

connorgmeehan commented Oct 11, 2022

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
Copy link

This is still an issue...

@kgreunke
Copy link
Author

kgreunke commented Aug 4, 2023

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants