From add1b10b79011d1af61419a63cc8ef4645f45bbf Mon Sep 17 00:00:00 2001 From: Jongwook Choi Date: Fri, 27 Oct 2023 09:17:46 -0400 Subject: 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. --- runtime/lua/vim/diagnostic.lua | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'runtime/lua/vim/diagnostic.lua') diff --git a/runtime/lua/vim/diagnostic.lua b/runtime/lua/vim/diagnostic.lua index 9e9b09ed1d..99448982b4 100644 --- a/runtime/lua/vim/diagnostic.lua +++ b/runtime/lua/vim/diagnostic.lua @@ -592,8 +592,10 @@ end --- * spacing: (number) Amount of empty spaces inserted at the beginning --- of the virtual text. --- * prefix: (string or function) prepend diagnostic message with prefix. ---- If a function, it must have the signature (diagnostic) -> string, ---- where {diagnostic} is of type |diagnostic-structure|. This can be +--- If a function, it must have the signature (diagnostic, i, total) +--- -> 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. --- * suffix: (string or function) Append diagnostic message with suffix. --- 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 local resolved_prefix = prefix if type(prefix) == 'function' then - resolved_prefix = prefix(line_diags[i]) or '' + resolved_prefix = prefix(line_diags[i], i, #line_diags) or '' end table.insert( virt_texts, -- cgit