:vertical_traffic_light: Diagnostics in the echo / message area
https://github.com/yochem/chime.nvim.git
Chime is a very little diagnostic handler that echoes the diagnostics of the current line to the echo / message area.
Chime is very configurable and aims to be as Neovim native as possible.
To install, use your favorite plugin manager. For example with lazy.nvim:
{ 'yochem/chime.nvim' }
For lazy-loading you could try event = 'DiagnosticsChanged', although the
plugin should be very light.
This plugin aims to do everything the Neovim way. Because it handles
diagnostics, it's an
diagnostic-handler.
This means configuration is handled using vim.diagnostic.config(), not
setup(). It also listens to global configuration options for diagnostic
handlers, and you can enable it only for certain namespaces. See
vim.diagnostic.config)
for more info.
vim.diagnostic.config({
chime = {
format = ...,
severity = nil,
severity_sort = false,
trim = true,
}
})
Set the format of the diagnostic message with the format config option. It
should be a function that receives a diagnostic and outputs either a string or
a list of colored chunks (like the first argument of
vim.api.nvim_echo())).
An example that returns the formatted string [INFO] Unused functions. (luals):
vim.diagnostic.config({
chime = {
format = function(diagnostic)
return ('[%s] %s (%s)'):format(
-- this assumes the default sign text
vim.diagnostic.severity[diagnostic.severity],
diagnostic.message,
diagnostic.source,
)
end
}
})
And the same diagnostic but with the sign text highlighted in its color and the source in gray:
vim.diagnostic.config({
chime = {
format = function(diagnostic)
local severity_text = vim.diagnostic.severity[diagnostic.severity]
local severity_color = ({
'DiagnosticError',
'DiagnosticWarn',
'DiagnosticInfo',
'DiagnosticHint',
})[diagnostic.severity]
return {
{ ('[%s] '):format(severity_text), severity_color },
-- prevent "Press enter" prompts by only showing first line
{ vim.split(diagnostic.message, '\n')[1] },
{ (' (%s)'):format(diagnostic.source), "Comment" },
}
end
}
})
Filter on severities, for example only show errors in Chime. See
diagnostic-severity.
Sort by severity. It is recommended to set this to true. See
vim.diagnostic.Opts.
The trim option defaults to true and trims the diagnostic message to fit
|v:echospace|, ensuring you'll never see the Press
ENTER prompt. You might set
this to false if you use the new extui / ui2 command line.
Chime can be enabled or disabled on the fly:
" disable Chime
:lua vim.diagnostic.config({ chime = false })
" and enable again
:lua vim.diagnostic.config({ chime = true })
May you wish to only manually show the diagnostics, disable the handler and map
the show() method yourself.
vim.diagnostic.config({ chime = false })
vim.keymap.set('n', '<leader>d', function()
require('chime').show()
end)
The main functionality of this plugin is inspired by seblyng/nvim-ech-diagnostics, which I have used with pleasure for some years. This plugin aims to have the same functionality as nvim-echo-diagnostics, but in a more modern Neovim way (by being a diagnostic handler). I figured this was to much of a breaking change to upstream to nvim-echo-diagnostics, so here we are.
cmdheight temporary to allow multiple diagnostics at once, withoutupdate_in_insert