mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
fix(diagnostic): virtual_text prefix function should have index and total (#25801)
The prefix option of the diagnostic virtual text can be a function, but previously it was only a function of diagnostic. This function should also have additional parameters index and total, more consistently and similarily as in the prefix function for `vim.diagnostic.open_float()`. These additional parameters will be useful when there are too many number of diagnostics in a single line.
This commit is contained in:
parent
4fcdfa5ad0
commit
add1b10b79
@ -404,9 +404,12 @@ config({opts}, {namespace}) *vim.diagnostic.config()*
|
|||||||
the beginning of the virtual text.
|
the beginning of the virtual text.
|
||||||
• prefix: (string or function) prepend diagnostic
|
• prefix: (string or function) prepend diagnostic
|
||||||
message with prefix. If a function, it must have the
|
message with prefix. If a function, it must have the
|
||||||
signature (diagnostic) -> string, where {diagnostic}
|
signature (diagnostic, i, total) -> string, where
|
||||||
is of type |diagnostic-structure|. This can be used
|
{diagnostic} is of type |diagnostic-structure|, {i}
|
||||||
to render diagnostic symbols or error codes.
|
is the index of the diagnostic being evaluated, and
|
||||||
|
{total} is the total number of diagnostics for the
|
||||||
|
line. This can be used to render diagnostic symbols
|
||||||
|
or error codes.
|
||||||
• suffix: (string or function) Append diagnostic
|
• suffix: (string or function) Append diagnostic
|
||||||
message with suffix. If a function, it must have the
|
message with suffix. If a function, it must have the
|
||||||
signature (diagnostic) -> string, where {diagnostic}
|
signature (diagnostic) -> string, where {diagnostic}
|
||||||
|
@ -592,8 +592,10 @@ end
|
|||||||
--- * spacing: (number) Amount of empty spaces inserted at the beginning
|
--- * spacing: (number) Amount of empty spaces inserted at the beginning
|
||||||
--- of the virtual text.
|
--- of the virtual text.
|
||||||
--- * prefix: (string or function) prepend diagnostic message with prefix.
|
--- * prefix: (string or function) prepend diagnostic message with prefix.
|
||||||
--- If a function, it must have the signature (diagnostic) -> string,
|
--- If a function, it must have the signature (diagnostic, i, total)
|
||||||
--- where {diagnostic} is of type |diagnostic-structure|. This can be
|
--- -> string, where {diagnostic} is of type |diagnostic-structure|,
|
||||||
|
--- {i} is the index of the diagnostic being evaluated, and {total}
|
||||||
|
--- is the total number of diagnostics for the line. This can be
|
||||||
--- used to render diagnostic symbols or error codes.
|
--- used to render diagnostic symbols or error codes.
|
||||||
--- * suffix: (string or function) Append diagnostic message with suffix.
|
--- * suffix: (string or function) Append diagnostic message with suffix.
|
||||||
--- If a function, it must have the signature (diagnostic) ->
|
--- If a function, it must have the signature (diagnostic) ->
|
||||||
@ -1072,7 +1074,7 @@ function M._get_virt_text_chunks(line_diags, opts)
|
|||||||
for i = 1, #line_diags do
|
for i = 1, #line_diags do
|
||||||
local resolved_prefix = prefix
|
local resolved_prefix = prefix
|
||||||
if type(prefix) == 'function' then
|
if type(prefix) == 'function' then
|
||||||
resolved_prefix = prefix(line_diags[i]) or ''
|
resolved_prefix = prefix(line_diags[i], i, #line_diags) or ''
|
||||||
end
|
end
|
||||||
table.insert(
|
table.insert(
|
||||||
virt_texts,
|
virt_texts,
|
||||||
|
@ -1237,7 +1237,7 @@ end)
|
|||||||
return prefix .. message
|
return prefix .. message
|
||||||
]])
|
]])
|
||||||
|
|
||||||
eq('[err-code] Some error', exec_lua [[
|
eq('[(1/1) err-code] Some error', exec_lua [[
|
||||||
local diagnostics = {
|
local diagnostics = {
|
||||||
make_error('Some error', 0, 0, 0, 0, nil, 'err-code'),
|
make_error('Some error', 0, 0, 0, 0, nil, 'err-code'),
|
||||||
}
|
}
|
||||||
@ -1245,7 +1245,7 @@ end)
|
|||||||
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics, {
|
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics, {
|
||||||
underline = false,
|
underline = false,
|
||||||
virtual_text = {
|
virtual_text = {
|
||||||
prefix = function(diag) return string.format('[%s]', diag.code) end,
|
prefix = function(diag, i, total) return string.format('[(%d/%d) %s]', i, total, diag.code) end,
|
||||||
suffix = '',
|
suffix = '',
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user