mirror of
https://github.com/neovim/neovim
synced 2025-07-16 01:01:49 +00:00
fix(diagnostic): don't include diagnostic code when using custom formatter #32464
This commit is contained in:
committed by
GitHub
parent
906ad04ddd
commit
0e8e4a07f5
@ -1851,13 +1851,7 @@ local function render_virtual_lines(namespace, bufnr, diagnostics)
|
||||
-- b. Has enough space on the left.
|
||||
-- c. Is just one line.
|
||||
-- d. Is not an overlap.
|
||||
local msg ---@type string
|
||||
if diagnostic.code then
|
||||
msg = string.format('%s: %s', diagnostic.code, diagnostic.message)
|
||||
else
|
||||
msg = diagnostic.message
|
||||
end
|
||||
for msg_line in msg:gmatch('([^\n]+)') do
|
||||
for msg_line in diagnostic.message:gmatch('([^\n]+)') do
|
||||
local vline = {}
|
||||
vim.list_extend(vline, left)
|
||||
vim.list_extend(vline, center)
|
||||
@ -1882,6 +1876,16 @@ local function render_virtual_lines(namespace, bufnr, diagnostics)
|
||||
end
|
||||
end
|
||||
|
||||
--- Default formatter for the virtual_lines handler.
|
||||
--- @param diagnostic vim.Diagnostic
|
||||
local function format_virtual_lines(diagnostic)
|
||||
if diagnostic.code then
|
||||
return string.format('%s: %s', diagnostic.code, diagnostic.message)
|
||||
else
|
||||
return diagnostic.message
|
||||
end
|
||||
end
|
||||
|
||||
M.handlers.virtual_lines = {
|
||||
show = function(namespace, bufnr, diagnostics, opts)
|
||||
vim.validate('namespace', namespace, 'number')
|
||||
@ -1910,9 +1914,8 @@ M.handlers.virtual_lines = {
|
||||
|
||||
api.nvim_clear_autocmds({ group = ns.user_data.virt_lines_augroup, buffer = bufnr })
|
||||
|
||||
if opts.virtual_lines.format then
|
||||
diagnostics = reformat_diagnostics(opts.virtual_lines.format, diagnostics)
|
||||
end
|
||||
diagnostics =
|
||||
reformat_diagnostics(opts.virtual_lines.format or format_virtual_lines, diagnostics)
|
||||
|
||||
if opts.virtual_lines.current_line == true then
|
||||
-- Create a mapping from line -> diagnostics so that we can quickly get the
|
||||
|
Reference in New Issue
Block a user