Hi, new to neovim/LSP here. I was directed to the forums from issue 16627. I have been reading through the vim and lsp codebases, help pages, issues at github and threads in this forum. I wasn’t able to solve my “problem”. Please bear with my noob question.
I would like to know where is a good place to retrieve the severity level (I want to change the border color depending on severity level). My idea was to intercept it either in diagnostic.open_float
or lsp.util.open_floating_preview
but these are probably not the places for this. I was told in the issue, that I need to look at nvim_open_win
but I don’t understand how that might help, since LSP diagnostics doesn’t call nvim_open_win
directly (if I understood correctly), and it doesn’t have the severity info anyway.
My current code is:
-- Show line diagnostics in floating popup on hover, except insert mode (CursorHoldI)
vim.o.updatetime = 250
vim.cmd [[autocmd CursorHold * lua vim.diagnostic.open_float(nil, {focus=false})]]
-- Show source in diagnostics, not inline but as a floating popup
vim.diagnostic.config({
virtual_text = false,
float = {
source = "always", -- Or "if_many"
},
})
-- create an array to hold custom border styles
local border = {
{"🭽", "LspFloatWinBorder"},
{"▔", "LspFloatWinBorder"},
{"🭾", "LspFloatWinBorder"},
{"▕", "LspFloatWinBorder"},
{"🭿", "LspFloatWinBorder"},
{"▁", "LspFloatWinBorder"},
{"🭼", "LspFloatWinBorder"},
{"▏", "LspFloatWinBorder"},
}
-- modify open_floating_preview to use the custom borders
local orig_util_open_floating_preview = vim.lsp.util.open_floating_preview
local open_floating_preview_custom = function(contents, syntax, opts, ...)
opts = opts or {}
-- Ideally I would like to retrieve severity here, to use that border array or another one.
opts.border = opts.border or border
return orig_util_open_floating_preview(contents, syntax, opts, ...)
end
vim.lsp.util.open_floating_preview = open_floating_preview_custom
I think adding a plugin to only do that, as also suggested in the issue, is way overkill (besides, no plugin that I know of does this).
Thank you for your attention.
Sergi