I really like the format of the diagnostics, however it shifts around all of the lines everytime a new diagnostic is shown. also when scrolling through a window and jumping over a line that is full of diagnostics, the window jumps around because it skips a whole bunch of lines.
I get, that having all diagnostics shown all of the time in a floating window overlaps with the code that you're trying to edit. That being said, do you see an option of making the diagnostics float, so that the visual changes are not shown on their own lines?
If you have lots of diagnostics, they might end up covering all the code you're trying to work on. I'm not sure I understand what you're asking for.
When scrolling through files with large amount of diagnostics, it's handy to just hide the inline ones via a mapping.
The IDE way would be to just show the underline by default and show the diagnostics in a floating window, when the mouse (in vim the cursor) hovers over the diagnostic. This behavior could also be a config option!
it’s handy to just hide the inline ones via a mapping
What do you mean by the inline ones?
I think you just want the floating windows that neovim already ships.
vim.lsp.buf.hover()
Just trigger that with an autocmd on
CursorHold
.
I very much want something that will trigger on a
CursorHold
autocmd, but I'd like for it to display inside of a floating window instead of virtual lines because I find all of the "thrash" to be kind of jarring with diagnostics popping in and out as I scroll through my file.I don't think
vim.lsp.buf.hover
is exactly what we want because doesn't always contain diagnostic information. My config has it usually populating with type information for whatever symbol is under the cursor. I think thatvim.lsp.util.open_floating_preview()
might be more appropriate, although I'm currently encountering 2 issues with getting it to work:
- Unless I'm reading something wrong, I don't see a good way to invoke LSP Lines for a given line.
vim.lsp.util.open_floating_preview
accepts a table of text to render, so ideally I'd be able to do something likevim.lsp.util.open_floating_preview(lsp_lines.get_diag_for_line(vim.api.nvim_get_current_line(), ... )
- The second argument of
open_floating_preview
is a syntax to string to set for the preview window, and I'm not sure if there's going to be a way to nicely highlight everything we'd want to include.I was able to hack together a quick illustration of basically what I'm going for here.
vim.lsp.util.open_floating_preview( {vim.api.nvim_get_current_line(), ' └──── Unused local `lsp`.'}, 'lua', { width = 50, height = 2, focusable = false, wrap = false} )
I think it might require some refactoring in the
render.lua
in order to get a function that can just return a table of diagnostic lines. I get that this functionality is not something you're particularly looking for, but would you be open to a PR that does this? If so, I might take a crack at it.EDIT: Also, it's entirely possible that I've misunderstood something here. I've not used any of Neovim's floating window APIs before and haven't had a chance to really dig into
lsp_lines.render.show
and grok what's going on in there. Feel free to correct me if I'm missing something 😅
I would be interested in this as well. Virtual lines tend to mess up the cursor placement if there are plenty of adjacent lines with diagnostics on them. It doesn't really matter that a floating diagnostic window would hide lines under the current line since they usually aren't relevant when you're looking at diagnostics.