diagnostic-nvim
diagnostic-nvim copied to clipboard
Triggering diagnostics in a new file not on disk spams error messages
Hi,
This bug might be in neovim, however I can't get it reproduced without your plugin as I'm failing to navigate the undocumented vim.api.lsp calls. If you can figure it out I'd be very grateful!
Test steps I used:
- Make sure
sumneko_lspserver is set up and working - Edit a new file:
:e mytestfile.lua - Insert some text to trigger a diagnostic:
local foo(should trigger a variable not used Hint)
The messages bar will then show:
Error executing vim.schedule lua callback: /usr/local/share/nvim/runtime/lua/vim/lsp/util.lua:1018: bad argument #1 to 'lines' (/home/gecko/.config/nvim/mytestfile.lua: No such file or directory)
Unfortunately this error is very aggressive and can make editing, or even controlling nvim, impossible.
Using up to date nightly nvim and this repo.
Should be fixed by the latest commit. Please update and check:)
This works, but now I don't receive diagnostic messages until the file is written. There is no virtual text, and using :OpenDiagnostic results in an error because the location list is empty.
Is this something that needs to be fixed in neovim itself?
Hmm looks like an issue on my side since I can't reproduce without diagnostic-nvim. I'll look into it.
Could you share the steps you use to try to reproduce? Then I can try too.
I think I found the cause. Initially my fix was disabling diagnostic when buffer doesn't exist in disk(which leads to the current result). But then I found out the default behavior does have diagnostic even when buffer doesn't exit... so I went to compare my custom callback with neovim's. I found out the cause is the built-in locations_to_items will not work properly in this case(which I use that function to put diagnostic items to location list), so disabling location list will fix this issues. I don't know this is the nature of location list or something in locations_to_items went wrong.
My latest commit fix this by disabling location_to_items when buffer doesn't exist. You can still see other error message but can't jump around using location list(and OpenDiagnostic will not work). I'll look into the location_to_items function and see if I can find the cause:)
The line in my original error message in locations_to_items does try to open a file on disk: for line in io.lines(fname) do. It's not clear to me whether that just means locations_to_items isn't supposed to be used inside unwritten buffers, or whether that's an oversight in the function and that neovim should either be reading directly from the buffer into the lua code, or temporarily writing the file to disk.
Hmm maybe that means I should create my own locations_to_items... I think locations_to_items was intended to use with goto definitions and stuff, which the location of those files might not be loaded by neovim so it's requires to read from files.
Sorry for the wait..but the latest commit should fix this issue.