Is it possible, using the new vim.diagnostic
API, to limit the contents of the floating diagnostic window to only diagnostics on the current line?
I tried the config below, but it just shows the default message and the custom function doesn’t seem to be used at all:
vim.diagnostic.config({
severity_sort = true,
virtual_text = {
severity = { min = vim.diagnostic.severity.WARN },
},
float = function(ns, bufnr)
if bufnr == vim.api.nvim_get_current_buf() then
local curr_line = vim.fn.line('.')
return {
format = function(diagnostic)
if diagnostic.lnum <= curr_line and diagnostic.end_lnum >= curr_line then
return ("[%s:%s] (%d:%d - %d:%d) %s"):format(
diagnostic.source or "?",
(diagnostic.severity and severity_names[diagnostic.severity]) or "?",
diagnostic.lnum or "?",
diagnostic.col or "?",
diagnostic.end_lnum or "?",
diagnostic.end_col or "?",
diagnostic.message
)
end
end
}
end
end,
})