| README.md | ||
Tiny inline diagnostics with tiny-inline-diagnostic.nvim
The Problem
Per default LSP errors are displayed as virtual_text in the same line as where the error occurs:
Also per default virtual_text is not wrapped, it is simply cut off where the window ends.
Depending on how many errors / warnings you have in your file, the lsp messages can get quite chatty and annoying.
What we want to have instead is to
-
have the full lsp error message
-
see the error message only for the current line we're in
The Solution
We are going to install a plugin that goes by the name tiny-inline-diagnostic.nvim which, when installed correctly, will solve both of our problems.
We will have the full lsp message, in a nice and clean interface, only where our cursor is blinking.
Load the tiny-inline-diagnostic package with LazyVim
Put this code at the end of .config/nvim/lua/plugins/init.lua:
-- .config/nvim/lua/plugins/init.lua
-- ...
{
"rachartier/tiny-inline-diagnostic.nvim",
event = "VeryLazy", -- Or `LspAttach`
priority = 1000, -- needs to be loaded in first
config = function()
require('tiny-inline-diagnostic').setup()
vim.diagnostic.config({ virtual_text = false }) -- Only if needed in your configuration, if you already have native LSP diagnostics
end
},
Require tiny-inline-diagnostic
make sure to require tiny-inline-diagnostic by adding those lines to your .config/nvim/init.lua
-- .config/nvim/init.lua
-- ...
require("tiny-inline-diagnostic").setup({
-- ...
signs = {
left = "",
right = "",
diag = "●",
arrow = " ",
up_arrow = " ",
vertical = " │",
vertical_end = " └",
},
blend = {
factor = 0.22,
},
-- ...
})
vim.diagnostic.config - set virtual_text to false
chadrc.lua won't work
In some tutorials you might see that people put this code into the chadrc.lua file. As of today this leads to chadrc.lua not being applied correctly when nvim starts: virtual_text = false has no effect and we still see all the clutter. The problem is discussed here.
The solution is to put these lines not into chadrc.lua, but into lspconfig.lua, right after all LSPs are set up and loaded.
lspconfig.lua is the right place
Put this code at the end of the file:
-- .config/nvim/lua/configs/lspconfig.lua
-- ...
vim.diagnostic.config(
{
underline = false,
virtual_text = false,
update_in_insert = false,
severity_sort = true,
signs = {
text = {
[vim.diagnostic.severity.ERROR] = " ",
[vim.diagnostic.severity.WARN] = " ",
[vim.diagnostic.severity.HINT] = " ",
[vim.diagnostic.severity.INFO] = " ",
}
}
}
)
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
virtual_text = false,
})

