Vim.diagnostic.show and vim.diagnostic.open_float not working [solved]

I’m quite new to Neovim and I’m experimenting with my configuration. Thanks to everyone working on Neovim!

I just realized that neither :lua vim.diagnostic.show() or:lua vim.diagnostic.open_float() works for me. I have a buffer with an unused variable ‘foobar’, but nothing happens when those commands are called. I get no window with an ‘Unused local foobar’ warning. But the command lua vim.diagnostic.setloclist() works fine and lists the warning ‘Unused local foobar’ in a setloclist window.

I’ve got lua_ls installed and configured, and :LspInfo reports that the buffer is attached to the Lua language server. I’m running Neovim v0.9.5. Any idea of what could be the problem or where I should start looking?

1 Like

:LspInfo reports that the buffer is attached to the Lua language server

To make sure there aren’t any misunderstandings: the LSP client is attached to the buffer

I’ve got lua_ls installed and configured

It would be helpful if you showed how your LSP is set up.

I just realized that neither :lua vim.diagnostic.show() or :lua vim.diagnostic.open_float() works for me. I have a buffer with an unused variable ‘foobar’, but nothing happens when those commands are called. I get no window with an ‘Unused local foobar’ warning.

  • As for :lua vim.diagnostic.show(): Can you attach screenshot of a buffer with some errors/warnings?
    Something like that:

    I want to know if you have this virtual text on a line with problem.
    The presence of this text means that vim.diagnostic.show() has been run at some moment. If it is not the case, you can try vim.diagnostic.enable(0) (0 for current buffer id)
  • As for :lua vim.diagnostic.open_float() make sure that you run it on a line with a problem.
    It should look something like this:

    Or you can try :lua =vim.diagnostic.open_float() to see if there is some output:
1 Like

To make sure there aren’t any misunderstandings: the LSP client is attached to the buffer

Yes. Sorry for being fuzzy.

Thanks for your reply and helpful questions.

  • Yes, I get the virtual text ‘H’ on a line with a problem. I now realize that this means that diagnostics are enabled. And that vim.diagnostic.enable(0) and vim.diagnostic.disable(0) are used to turn that feature on and off, and also that vim.diagnostic.show() has been run and works, since I see the virtual text ‘H’. I thought that vim.diagnostic.show() would show all diagnostics for the current buffer in a new window. I thought vim.diagnostic.show() was a Neovim alternative to Vims setloclist().

  • Yes, :lua vim.diagnostic.open_float() works when I run it on a line with a problem. I thought it would open a floating window with all problems/diagnostics in the buffer, irrespective of which line I was on.

So, everything seems to work for me. Thanks for the help nikita-talalai. Sometimes asking questions is the best help! I’ll try to RTFM more diligently!

1 Like