Skip to content
This repository has been archived by the owner on Jul 6, 2021. It is now read-only.

Triggering diagnostics in a new file not on disk spams error messages #28

Open
skyegecko opened this issue Jun 2, 2020 · 9 comments
Open
Labels
bug Something isn't working

Comments

@skyegecko
Copy link

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:

  1. Make sure sumneko_lsp server is set up and working
  2. Edit a new file: :e mytestfile.lua
  3. 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.

@haorenW1025 haorenW1025 added the bug Something isn't working label Jun 3, 2020
@haorenW1025
Copy link
Collaborator

Should be fixed by the latest commit. Please update and check:)

@skyegecko
Copy link
Author

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?

@haorenW1025
Copy link
Collaborator

Hmm looks like an issue on my side since I can't reproduce without diagnostic-nvim. I'll look into it.

@skyegecko
Copy link
Author

Could you share the steps you use to try to reproduce? Then I can try too.

@haorenW1025
Copy link
Collaborator

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.

@haorenW1025
Copy link
Collaborator

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:)

@skyegecko
Copy link
Author

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.

@haorenW1025
Copy link
Collaborator

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.

@haorenW1025
Copy link
Collaborator

Sorry for the wait..but the latest commit should fix this issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants