diff options
author | beardedsakimonkey <54521218+beardedsakimonkey@users.noreply.github.com> | 2022-11-20 23:57:36 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-20 16:57:36 -0700 |
commit | 126ef65e5b3ff0da68bfe166be0bb0a33664142b (patch) | |
tree | f47d165c647ab7c5665d51ff618a8d07a92a4ce7 /runtime/lua/vim/diagnostic.lua | |
parent | fbce9f421ad1ad466126a24524ade9df978486d5 (diff) | |
download | rneovim-126ef65e5b3ff0da68bfe166be0bb0a33664142b.tar.gz rneovim-126ef65e5b3ff0da68bfe166be0bb0a33664142b.tar.bz2 rneovim-126ef65e5b3ff0da68bfe166be0bb0a33664142b.zip |
feat(diagnostic): add `suffix` option to `virt_text` config (#21140)
This introduces a `suffix` option to the `virt_text` config in
`vim.diagnostic.config()`. The suffix can either be a string which is appended
to the diagnostic message or a function returning such. The function receives a
`diagnostic` argument, which is the diagnostic table of the last diagnostic (the
one whose message is rendered as virt text).
Diffstat (limited to 'runtime/lua/vim/diagnostic.lua')
-rw-r--r-- | runtime/lua/vim/diagnostic.lua | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/runtime/lua/vim/diagnostic.lua b/runtime/lua/vim/diagnostic.lua index 008b00a9a0..a7fc47a5a8 100644 --- a/runtime/lua/vim/diagnostic.lua +++ b/runtime/lua/vim/diagnostic.lua @@ -613,6 +613,10 @@ end --- * spacing: (number) Amount of empty spaces inserted at the beginning --- of the virtual text. --- * prefix: (string) Prepend diagnostic message with prefix. +--- * 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|. +--- This can be used to render an LSP diagnostic error code. --- * format: (function) A function that takes a diagnostic as input and --- returns a string. The return value is the text used to display --- the diagnostic. Example: @@ -1039,6 +1043,7 @@ function M._get_virt_text_chunks(line_diags, opts) opts = opts or {} local prefix = opts.prefix or '■' + local suffix = opts.suffix or '' local spacing = opts.spacing or 4 -- Create a little more space between virtual text and contents @@ -1052,8 +1057,11 @@ function M._get_virt_text_chunks(line_diags, opts) -- TODO(tjdevries): Allow different servers to be shown first somehow? -- TODO(tjdevries): Display server name associated with these? if last.message then + if type(suffix) == 'function' then + suffix = suffix(last) or '' + end table.insert(virt_texts, { - string.format('%s %s', prefix, last.message:gsub('\r', ''):gsub('\n', ' ')), + string.format('%s %s%s', prefix, last.message:gsub('\r', ''):gsub('\n', ' '), suffix), virtual_text_highlight_map[last.severity], }) |