E5108: Error executing lua [string ":lua"]:1: attempt to call field 'show_line_diagnostics' (a nil value)
stack traceback:
[string ":lua"]:1: in main chunk
I personally use this to show diagnostics only if there is no other floating window (for example, autocompletion) open and shown, so that they don’t overlap:
-- Function to check if a floating dialog exists and if not
-- then check for diagnostics under the cursor
function OpenDiagnosticIfNoFloat()
for _, winid in pairs(vim.api.nvim_tabpage_list_wins(0)) do
if vim.api.nvim_win_get_config(winid).zindex then
return
end
end
-- THIS IS FOR BUILTIN LSP
vim.diagnostic.open_float(0, {
scope = "cursor",
focusable = false,
close_events = {
"CursorMoved",
"CursorMovedI",
"BufHidden",
"InsertCharPre",
"WinLeave",
},
})
end
-- Show diagnostics under the cursor when holding position
vim.api.nvim_create_augroup("lsp_diagnostics_hold", { clear = true })
vim.api.nvim_create_autocmd({ "CursorHold" }, {
pattern = "*",
command = "lua OpenDiagnosticIfNoFloat()",
group = "lsp_diagnostics_hold",
})