Tweak LSP's diagnostic floating window position

Hi there ! ncm2 made the very useful float-preview.nvim plugin, that lets the omnifunc floating window move away from one’s “eyespot”, as they call it (I think eyespot is quite a powerful concept anyway).

I’d like to have something similar for the diagnostic preview window. But I wish I didn’t do it the same ; float-preview listens on CompleteChanged and reformats the originating window. Formatting the floating window twice seems to me like a waste of precious time.

Is there some way to provide options for the call to nvim_open_win() inside the nvim.lsp interface ? I digged into vim.lsp.diagnostic.goto_next()'s options, and couldn’t find one verbatim. I even tried

vim.lsp.diagnostic.goto_next({ enable_popup = my_preview_function })

but with no success. I guess goto_next calls vim.lsp.util.open_floating_preview() ; does someone know of a way to override it ?

I found out that I could modify a single line in runtime/lua/vim/lsp/util.lua, namely from

    relative = 'cursor',

to

    relative = opts.relative or 'cursor',

would let me pass relative = "win" in the popup_opts of eg vim.lsp.diagnostic.goto_next() - and the popup does behave accordingly. This goes in the direction I mentioned ; anchor could be opened to custom popup_opts as well, although it didn’t behave as I expected - I hoped it would help dock the floating window to the top right of the buffer with

anchor = "NE"

And now I wonder if it’s a good idea to let users or plugins totally control the float-preview position. make_floating_popup_options() has some clever tricks to set the col, row and anchor for the cursor-positioned popup, wouldn’t it be better to implement the same for a sane docked default and let users switch to it by a docked option in popup_opts ? Comments welcome before I try and build up on this !

Well, I’ve been using this today; doesn’t seem so useful after all. The thing is that sometimes I can’t properly see to which line it applies, since the cursor just jumped to the offending line. Could do with a pulse on the jumped-to line, like in the vim-search-pulse plugin. But that would be a bit too many things opening and pulsing at the same time for my taste anyway.