15

i ran into a problem, when im using neovim (+ lspconfig with hie set up), i have diagnostics info inline, but sometime, i cant read the whole line: enter image description here

is there a way for me to see the whole message? i searched on the net to find a way to put the message on a floating window/status line when i hover the line, but i couldnt find a solution.

thanks for your help!

Nathan
  • 493
  • 1
  • 3
  • 13

2 Answers2

20

To disable inline text, and do a diagnostic window on hover, just put these lines into lsp config:

vim.diagnostic.config({
  virtual_text = false
})

-- Show line diagnostics automatically in hover window
vim.o.updatetime = 250
vim.cmd [[autocmd CursorHold,CursorHoldI * lua vim.diagnostic.open_float(nil, {focus=false})]]

More info can be found here: https://github.com/neovim/nvim-lspconfig/wiki/UI-Customization

enter image description here

mrded
  • 4,674
  • 2
  • 34
  • 36
  • 1
    Thanks, the diagnostic window is visible now, but the virtual text is shown yet :(. – Remy Ticona Feb 05 '22 at 02:02
  • If you want to disable the virtual text, use `vim.diagnostic.disable()`. Refer to [the docs](https://neovim.io/doc/user/diagnostic.html#:~:text=disable(%7Bbufnr%7D%2C%20%7Bnamespace%7D)-,vim.diagnostic.disable(),-Disable%20diagnostics%20in) for more info – Ali BEN AMOR Jan 05 '23 at 17:35
  • @Ali BEN AMOR that disables diagnostics completely. – mrded Jan 06 '23 at 19:48
  • I tried it and it works. As far as I understood his question, he wants only the floating panel to have the messages. So disabling the default one works (at least for me). This is how I did it : `vim.diagnostic.disable()` `vim.cmd [[autocmd CursorHold,CursorHoldI * lua vim.diagnostic.open_float(nil, {focus=false})]]` – Ali BEN AMOR Jan 06 '23 at 21:16
18

The <cmd>lua vim.lsp.diagnostic.show_line_diagnostics() command shows the full diagnostics in a floating window: enter image description here

I bound the command to \<space>e as shown in the lspconfig github README and everything works fine.

EDIT 9 may 2022: In this commit, vim.lsp.diagnostic.show_line_diagnostics() changed to vim.diagnostic.open_float(), thanks @DarthVanger for pointing it out.

Dave Powers
  • 2,051
  • 2
  • 30
  • 34
Nathan
  • 493
  • 1
  • 3
  • 13
  • yeah. this is the only way where you can the virtual text from error wrapped very well to fit into the screen and to see the entire message – alexzander Oct 13 '21 at 10:53
  • The linked github doesn't have `show_line_diagnostics()` binding example. I've ended up adding `buf_map(bufnr, "n", "e", "lua vim.lsp.diagnostic.show_line_diagnostics()")` to `on_attach` in my `nvim` config – DarthVanger May 09 '22 at 11:46