aboutsummaryrefslogtreecommitdiff
path: root/test/functional/lua/diagnostic_spec.lua
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2024-04-15 18:35:59 +0200
committerJustin M. Keyes <justinkz@gmail.com>2024-04-15 21:32:31 +0200
commit5ed9916a28b9a09d2e5629f3e4e5b0e81403ded7 (patch)
treee4625022a73f20c8e18c21429c0e3cf96f562b64 /test/functional/lua/diagnostic_spec.lua
parent26765e8461c1ba1e9a351632212cf89900221781 (diff)
downloadrneovim-5ed9916a28b9a09d2e5629f3e4e5b0e81403ded7.tar.gz
rneovim-5ed9916a28b9a09d2e5629f3e4e5b0e81403ded7.tar.bz2
rneovim-5ed9916a28b9a09d2e5629f3e4e5b0e81403ded7.zip
feat(diagnostic): enable(…, opts)
Problem: vim.diagnostic.enable() does not match the signature of vim.lsp.inlay_hint.enable() Solution: - Change the signature so that the first 2 args are (bufnr, enable). - Introduce a 3rd `opts` arg. - Currently it only supports `opts.ns_id`.
Diffstat (limited to 'test/functional/lua/diagnostic_spec.lua')
-rw-r--r--test/functional/lua/diagnostic_spec.lua87
1 files changed, 62 insertions, 25 deletions
diff --git a/test/functional/lua/diagnostic_spec.lua b/test/functional/lua/diagnostic_spec.lua
index 972e2baa71..1a87d159c7 100644
--- a/test/functional/lua/diagnostic_spec.lua
+++ b/test/functional/lua/diagnostic_spec.lua
@@ -329,7 +329,7 @@ describe('vim.diagnostic', function()
eq(
{ 1, 1, 2, 0, 2 },
exec_lua [[
- vim.diagnostic.enable(diagnostic_bufnr, diagnostic_ns, false)
+ vim.diagnostic.enable(diagnostic_bufnr, false, { ns_id = diagnostic_ns })
return {
count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns),
count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.WARN, other_ns),
@@ -344,7 +344,7 @@ describe('vim.diagnostic', function()
eq(
all_highlights,
exec_lua([[
- vim.diagnostic.enable(diagnostic_bufnr, diagnostic_ns)
+ vim.diagnostic.enable(diagnostic_bufnr, true, { ns_id = diagnostic_ns })
return {
count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns),
count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.WARN, other_ns),
@@ -371,7 +371,7 @@ describe('vim.diagnostic', function()
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, ns_1_diags)
vim.diagnostic.set(other_ns, diagnostic_bufnr, ns_2_diags)
- vim.diagnostic.enable(diagnostic_bufnr, diagnostic_ns, false)
+ vim.diagnostic.enable(diagnostic_bufnr, false, { ns_id = diagnostic_ns })
return {
count_extmarks(diagnostic_bufnr, diagnostic_ns),
@@ -383,8 +383,8 @@ describe('vim.diagnostic', function()
eq(
{ 4, 0 },
exec_lua [[
- vim.diagnostic.enable(diagnostic_bufnr, diagnostic_ns)
- vim.diagnostic.enable(diagnostic_bufnr, other_ns, false)
+ vim.diagnostic.enable(diagnostic_bufnr, true, { ns_id = diagnostic_ns })
+ vim.diagnostic.enable(diagnostic_bufnr, false, { ns_id = other_ns })
return {
count_extmarks(diagnostic_bufnr, diagnostic_ns),
@@ -478,7 +478,7 @@ describe('vim.diagnostic', function()
end)
describe('enable() and disable()', function()
- it('works without arguments', function()
+ it('without arguments', function()
local result = exec_lua [[
vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
@@ -500,7 +500,7 @@ describe('vim.diagnostic', function()
table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
count_extmarks(diagnostic_bufnr, other_ns))
- vim.diagnostic.enable(nil, nil, false)
+ vim.diagnostic.enable(nil, false)
table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
count_extmarks(diagnostic_bufnr, other_ns))
@@ -532,7 +532,7 @@ describe('vim.diagnostic', function()
eq(4, result[4])
end)
- it('works with only a buffer argument', function()
+ it('with buffer argument', function()
local result = exec_lua [[
local other_bufnr = vim.api.nvim_create_buf(true, false)
@@ -561,7 +561,7 @@ describe('vim.diagnostic', function()
count_extmarks(diagnostic_bufnr, other_ns) +
count_extmarks(other_bufnr, diagnostic_ns))
- vim.diagnostic.enable(diagnostic_bufnr, nil, false)
+ vim.diagnostic.enable(diagnostic_bufnr, false)
table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
count_extmarks(diagnostic_bufnr, other_ns) +
@@ -573,7 +573,7 @@ describe('vim.diagnostic', function()
count_extmarks(diagnostic_bufnr, other_ns) +
count_extmarks(other_bufnr, diagnostic_ns))
- vim.diagnostic.enable(other_bufnr, nil, false)
+ vim.diagnostic.enable(other_bufnr, false)
table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
count_extmarks(diagnostic_bufnr, other_ns) +
@@ -588,7 +588,7 @@ describe('vim.diagnostic', function()
eq(3, result[4])
end)
- it('works with only a namespace argument', function()
+ it('with a namespace argument', function()
local result = exec_lua [[
vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
@@ -610,17 +610,17 @@ describe('vim.diagnostic', function()
table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
count_extmarks(diagnostic_bufnr, other_ns))
- vim.diagnostic.enable(nil, diagnostic_ns, false)
+ vim.diagnostic.enable(nil, false, { ns_id = diagnostic_ns })
table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
count_extmarks(diagnostic_bufnr, other_ns))
- vim.diagnostic.enable(nil, diagnostic_ns)
+ vim.diagnostic.enable(nil, true, { ns_id = diagnostic_ns })
table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
count_extmarks(diagnostic_bufnr, other_ns))
- vim.diagnostic.enable(nil, other_ns, false)
+ vim.diagnostic.enable(nil, false, { ns_id = other_ns })
table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
count_extmarks(diagnostic_bufnr, other_ns))
@@ -634,8 +634,11 @@ describe('vim.diagnostic', function()
eq(2, result[4])
end)
- it('works with both a buffer and a namespace argument', function()
- local result = exec_lua [[
+ --- @return table
+ local function test_enable(legacy)
+ local result = exec_lua(
+ [[
+ local legacy = ...
local other_bufnr = vim.api.nvim_create_buf(true, false)
vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
@@ -663,34 +666,68 @@ describe('vim.diagnostic', function()
count_extmarks(diagnostic_bufnr, other_ns) +
count_extmarks(other_bufnr, diagnostic_ns))
- vim.diagnostic.enable(diagnostic_bufnr, diagnostic_ns, false)
+ if legacy then
+ vim.diagnostic.disable(diagnostic_bufnr, diagnostic_ns)
+ else
+ vim.diagnostic.enable(diagnostic_bufnr, false, { ns_id = diagnostic_ns })
+ end
table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
count_extmarks(diagnostic_bufnr, other_ns) +
count_extmarks(other_bufnr, diagnostic_ns))
- vim.diagnostic.enable(diagnostic_bufnr, other_ns, false)
+ if legacy then
+ vim.diagnostic.disable(diagnostic_bufnr, other_ns)
+ else
+ vim.diagnostic.enable(diagnostic_bufnr, false, { ns_id = other_ns })
+ end
table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
count_extmarks(diagnostic_bufnr, other_ns) +
count_extmarks(other_bufnr, diagnostic_ns))
- vim.diagnostic.enable(diagnostic_bufnr, diagnostic_ns)
+ if legacy then
+ vim.diagnostic.enable(diagnostic_bufnr, diagnostic_ns)
+ else
+ vim.diagnostic.enable(diagnostic_bufnr, true, { ns_id = diagnostic_ns })
+ end
table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
count_extmarks(diagnostic_bufnr, other_ns) +
count_extmarks(other_bufnr, diagnostic_ns))
- -- Should have no effect
- vim.diagnostic.enable(other_bufnr, other_ns, false)
+ if legacy then
+ -- Should have no effect
+ vim.diagnostic.disable(other_bufnr, other_ns)
+ else
+ -- Should have no effect
+ vim.diagnostic.enable(other_bufnr, false, { ns_id = other_ns })
+ end
table.insert(result, count_extmarks(diagnostic_bufnr, diagnostic_ns) +
count_extmarks(diagnostic_bufnr, other_ns) +
count_extmarks(other_bufnr, diagnostic_ns))
return result
- ]]
+ ]],
+ legacy
+ )
+
+ return result
+ end
+
+ it('with both buffer and namespace arguments', function()
+ local result = test_enable(false)
+ eq(4, result[1])
+ eq(2, result[2])
+ eq(1, result[3])
+ eq(3, result[4])
+ eq(3, result[5])
+ end)
+ it('with both buffer and namespace arguments (deprecated signature)', function()
+ -- Exercise the legacy/deprecated signature.
+ local result = test_enable(true)
eq(4, result[1])
eq(2, result[2])
eq(1, result[3])
@@ -1742,7 +1779,7 @@ describe('vim.diagnostic', function()
eq(
0,
exec_lua [[
- vim.diagnostic.enable(diagnostic_bufnr, diagnostic_ns, false)
+ vim.diagnostic.enable(diagnostic_bufnr, false, { ns_id = diagnostic_ns })
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, {
make_error('Diagnostic From Server 1:1', 1, 1, 1, 1),
})
@@ -1753,7 +1790,7 @@ describe('vim.diagnostic', function()
eq(
2,
exec_lua [[
- vim.diagnostic.enable(diagnostic_bufnr, diagnostic_ns)
+ vim.diagnostic.enable(diagnostic_bufnr, true, { ns_id = diagnostic_ns })
return count_extmarks(diagnostic_bufnr, diagnostic_ns)
]]
)
@@ -2719,7 +2756,7 @@ describe('vim.diagnostic', function()
make_error('Diagnostic #1', 1, 1, 1, 1),
})
vim.api.nvim_set_current_buf(diagnostic_bufnr)
- vim.diagnostic.enable(nil, nil, false)
+ vim.diagnostic.enable(nil, false)
return {
vim.diagnostic.is_enabled(),
vim.diagnostic.is_enabled(diagnostic_bufnr),