diff options
author | Maria José Solano <majosolano99@gmail.com> | 2025-02-03 00:54:31 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-02-03 00:54:31 -0800 |
commit | 445ecca398401ab9cdada163865db6dee374dde3 (patch) | |
tree | bb5212329c4519924bd51c6aa649d978d288beec /test/functional/lua/diagnostic_spec.lua | |
parent | 3a2893015759396e5345a1a85e0427705e0570b4 (diff) | |
download | rneovim-445ecca398401ab9cdada163865db6dee374dde3.tar.gz rneovim-445ecca398401ab9cdada163865db6dee374dde3.tar.bz2 rneovim-445ecca398401ab9cdada163865db6dee374dde3.zip |
feat(diagnostic): format() can filter diagnostics by returning nil #32302
Diffstat (limited to 'test/functional/lua/diagnostic_spec.lua')
-rw-r--r-- | test/functional/lua/diagnostic_spec.lua | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/test/functional/lua/diagnostic_spec.lua b/test/functional/lua/diagnostic_spec.lua index 08c287735e..9a982a1c6d 100644 --- a/test/functional/lua/diagnostic_spec.lua +++ b/test/functional/lua/diagnostic_spec.lua @@ -2134,6 +2134,32 @@ describe('vim.diagnostic', function() end) ) end) + + it('can filter diagnostics by returning nil when formatting', function() + local result = exec_lua(function() + vim.diagnostic.config { + virtual_text = { + format = function(diagnostic) + if diagnostic.code == 'foo_err' then + return nil + end + return diagnostic.message + end, + }, + } + + vim.diagnostic.set(_G.diagnostic_ns, _G.diagnostic_bufnr, { + _G.make_error('An error here!', 0, 0, 0, 0, 'foo_server', 'foo_err'), + _G.make_error('An error there!', 1, 1, 1, 1, 'bar_server', 'bar_err'), + }) + + local extmarks = _G.get_virt_text_extmarks(_G.diagnostic_ns) + return extmarks + end) + + eq(1, #result) + eq(' An error there!', result[1][4].virt_text[3][1]) + end) end) describe('handlers.virtual_lines', function() |