~whynothugo/lsp_lines.nvim#27: 
Show diagnostics in floating window

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?

Status
REPORTED
Submitter
~tim-hilt
Assigned to
No-one
Submitted
1 year, 11 months ago
Updated
1 year, 10 months ago
Labels
No labels applied.

~whynothugo 1 year, 11 months ago

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.

~tim-hilt 1 year, 11 months ago

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?

~whynothugo 1 year, 11 months ago

I think you just want the floating windows that neovim already ships.

vim.lsp.buf.hover()

~whynothugo 1 year, 11 months ago

Just trigger that with an autocmd on CursorHold.

~thatdarnpat 1 year, 10 months ago*

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 that vim.lsp.util.open_floating_preview() might be more appropriate, although I'm currently encountering 2 issues with getting it to work:

  1. 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 like vim.lsp.util.open_floating_preview(lsp_lines.get_diag_for_line(vim.api.nvim_get_current_line(), ... )
  2. 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 😅

~spike_b 1 year, 10 months ago

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.

Register here or Log in to comment, or comment via email.