aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/doc/diagnostic.txt9
-rw-r--r--runtime/lua/vim/diagnostic.lua8
-rw-r--r--test/functional/lua/diagnostic_spec.lua4
3 files changed, 13 insertions, 8 deletions
diff --git a/runtime/doc/diagnostic.txt b/runtime/doc/diagnostic.txt
index e9ca9ee347..7f5c809ac3 100644
--- a/runtime/doc/diagnostic.txt
+++ b/runtime/doc/diagnostic.txt
@@ -404,9 +404,12 @@ config({opts}, {namespace}) *vim.diagnostic.config()*
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 used
- to render diagnostic symbols or error codes.
+ 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) -> string, where {diagnostic}
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,
diff --git a/test/functional/lua/diagnostic_spec.lua b/test/functional/lua/diagnostic_spec.lua
index 8deb2e0726..f061fac50a 100644
--- a/test/functional/lua/diagnostic_spec.lua
+++ b/test/functional/lua/diagnostic_spec.lua
@@ -1237,7 +1237,7 @@ end)
return prefix .. message
]])
- eq('[err-code] Some error', exec_lua [[
+ eq('[(1/1) err-code] Some error', exec_lua [[
local diagnostics = {
make_error('Some error', 0, 0, 0, 0, nil, 'err-code'),
}
@@ -1245,7 +1245,7 @@ end)
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics, {
underline = false,
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 = '',
}
})