aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/diagnostic.lua
diff options
context:
space:
mode:
authorIsak Samsten <isak@samsten.se>2023-04-17 13:53:34 +0200
committerGitHub <noreply@github.com>2023-04-17 12:53:34 +0100
commit07b60efd8058bb515998f50048b511d50f9671f8 (patch)
tree5a61d00334466eaaea87ce0f41b9da2a0c31ab8a /runtime/lua/vim/diagnostic.lua
parente83682e652ff68cf9a05f0076bb088e9231d2059 (diff)
downloadrneovim-07b60efd8058bb515998f50048b511d50f9671f8.tar.gz
rneovim-07b60efd8058bb515998f50048b511d50f9671f8.tar.bz2
rneovim-07b60efd8058bb515998f50048b511d50f9671f8.zip
feat(diagnostic): specify diagnostic virtual text prefix as a function
- vim.diagnostic.config() now accepts a function for the virtual_text.prefix option, which allows for rendering e.g., diagnostic severities differently.
Diffstat (limited to 'runtime/lua/vim/diagnostic.lua')
-rw-r--r--runtime/lua/vim/diagnostic.lua18
1 files changed, 14 insertions, 4 deletions
diff --git a/runtime/lua/vim/diagnostic.lua b/runtime/lua/vim/diagnostic.lua
index d1b50304c7..0d1d01b391 100644
--- a/runtime/lua/vim/diagnostic.lua
+++ b/runtime/lua/vim/diagnostic.lua
@@ -600,7 +600,10 @@ end
--- means to always show the diagnostic source.
--- * spacing: (number) Amount of empty spaces inserted at the beginning
--- of the virtual text.
---- * prefix: (string) Prepend diagnostic message with prefix.
+--- * 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.
--- * suffix: (string or function) Append diagnostic message with suffix.
--- If a function, it must have the signature (diagnostic) ->
--- string, where {diagnostic} is of type |diagnostic-structure|.
@@ -1066,8 +1069,15 @@ function M._get_virt_text_chunks(line_diags, opts)
-- Create a little more space between virtual text and contents
local virt_texts = { { string.rep(' ', spacing) } }
- for i = 1, #line_diags - 1 do
- table.insert(virt_texts, { prefix, virtual_text_highlight_map[line_diags[i].severity] })
+ for i = 1, #line_diags do
+ local resolved_prefix = prefix
+ if type(prefix) == 'function' then
+ resolved_prefix = prefix(line_diags[i]) or ''
+ end
+ table.insert(
+ virt_texts,
+ { resolved_prefix, virtual_text_highlight_map[line_diags[i].severity] }
+ )
end
local last = line_diags[#line_diags]
@@ -1078,7 +1088,7 @@ function M._get_virt_text_chunks(line_diags, opts)
suffix = suffix(last) or ''
end
table.insert(virt_texts, {
- string.format('%s %s%s', prefix, last.message:gsub('\r', ''):gsub('\n', ' '), suffix),
+ string.format(' %s%s', last.message:gsub('\r', ''):gsub('\n', ' '), suffix),
virtual_text_highlight_map[last.severity],
})