From 953ae71fd324eb1a263d2b7435cc15756b44ac2d Mon Sep 17 00:00:00 2001 From: Gregory Anders <8965202+gpanders@users.noreply.github.com> Date: Tue, 9 Nov 2021 14:33:01 -0700 Subject: feat(diagnostic): do not require namespace for hide() and show() (#16261) Also fix a few other small bugs regarding saving and restoring extmarks. In particular, now that the virtual text and underline handlers have their own dedicated namespaces, they should be responsible for saving and restoring their own extmarks. Also fix the wrong argument ordering in the call to `clear_diagnostic_cache` in the `on_detach` callback. --- test/functional/lua/diagnostic_spec.lua | 50 +++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'test/functional/lua') diff --git a/test/functional/lua/diagnostic_spec.lua b/test/functional/lua/diagnostic_spec.lua index e8bbee671e..bb2d39c8b2 100644 --- a/test/functional/lua/diagnostic_spec.lua +++ b/test/functional/lua/diagnostic_spec.lua @@ -268,6 +268,56 @@ describe('vim.diagnostic', function() ]]) end) + describe('show() and hide()', function() + it('works', function() + local result = exec_lua [[ + vim.api.nvim_win_set_buf(0, diagnostic_bufnr) + + local result = {} + + vim.diagnostic.config({ underline = false, virtual_text = true }) + + local ns_1_diags = { + make_error("Error 1", 1, 1, 1, 5), + make_warning("Warning on Server 1", 2, 1, 2, 5), + } + local ns_2_diags = { + make_warning("Warning 1", 2, 1, 2, 5), + } + + vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, ns_1_diags) + vim.diagnostic.set(other_ns, diagnostic_bufnr, ns_2_diags) + + -- Both + table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) + count_extmarks(diagnostic_bufnr, other_ns)) + + -- Hide one namespace + vim.diagnostic.hide(diagnostic_ns) + table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns)) + + -- Show one namespace + vim.diagnostic.show(diagnostic_ns) + table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns)) + + -- Hide all namespaces + vim.diagnostic.hide() + table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) + count_extmarks(diagnostic_bufnr, other_ns)) + + -- Show all namespaces + vim.diagnostic.show() + table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) + count_extmarks(diagnostic_bufnr, other_ns)) + + return result + ]] + + eq(3, result[1]) + eq(0, result[2]) + eq(2, result[3]) + eq(0, result[4]) + eq(3, result[5]) + end) + end) + describe('reset()', function() it('diagnostic count is 0 and displayed diagnostics are 0 after call', function() -- 1 Error (1) -- cgit