From 8122470f8310ae34bcd5e436e8474f9255eb16f2 Mon Sep 17 00:00:00 2001 From: Raphael Date: Wed, 13 Dec 2023 22:19:53 +0800 Subject: refactor(diagnostic): set sign by using extmark (#26193) after sign implementation refactor by using extmark, we can use `nvim_buf_set_extmark` to set diagnostic sign instead use `sign_define` --- test/functional/lua/diagnostic_spec.lua | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'test/functional/lua/diagnostic_spec.lua') diff --git a/test/functional/lua/diagnostic_spec.lua b/test/functional/lua/diagnostic_spec.lua index f061fac50a..e867ed32b0 100644 --- a/test/functional/lua/diagnostic_spec.lua +++ b/test/functional/lua/diagnostic_spec.lua @@ -1080,9 +1080,19 @@ end) table.insert(virt_texts, (string.gsub(virt_text[i][2], "DiagnosticVirtualText", ""))) end + local ns = vim.diagnostic.get_namespace(diagnostic_ns) + local sign_ns = ns.user_data.sign_ns local signs = {} - for _, v in ipairs(vim.fn.sign_getplaced(diagnostic_bufnr, {group = "*"})[1].signs) do - table.insert(signs, (string.gsub(v.name, "DiagnosticSign", ""))) + local all_signs = vim.api.nvim_buf_get_extmarks(diagnostic_bufnr, sign_ns, 0, -1, {type = 'sign', details = true}) + table.sort(all_signs, function(a, b) + return a[1] > b[1] + end) + + for _, v in ipairs(all_signs) do + local s = v[4].sign_hl_group:gsub('DiagnosticSign', "") + if not vim.tbl_contains(signs, s) then + signs[#signs + 1] = s + end end return {virt_texts, signs} @@ -1498,7 +1508,15 @@ end) vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics) - return vim.fn.sign_getplaced(diagnostic_bufnr, {group = '*'})[1].signs + local ns = vim.diagnostic.get_namespace(diagnostic_ns) + local sign_ns = ns.user_data.sign_ns + + local signs = vim.api.nvim_buf_get_extmarks(diagnostic_bufnr, sign_ns, 0, -1, {type ='sign', details = true}) + local result = {} + for _, s in ipairs(signs) do + result[#result + 1] = { lnum = s[2] + 1, name = s[4].sign_hl_group } + end + return result ]] eq({2, 'DiagnosticSignError'}, {result[1].lnum, result[1].name}) -- cgit From 29d5ff6ac4eade7996d14eec60a31ec6328a165d Mon Sep 17 00:00:00 2001 From: Gregory Anders Date: Wed, 13 Dec 2023 09:26:39 -0600 Subject: fix(diagnostic): check for sign namespace instead of sign group --- test/functional/lua/diagnostic_spec.lua | 57 +++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 21 deletions(-) (limited to 'test/functional/lua/diagnostic_spec.lua') diff --git a/test/functional/lua/diagnostic_spec.lua b/test/functional/lua/diagnostic_spec.lua index e867ed32b0..76963cc69e 100644 --- a/test/functional/lua/diagnostic_spec.lua +++ b/test/functional/lua/diagnostic_spec.lua @@ -1495,32 +1495,47 @@ end) ]]) end) - it('sets signs', function() - local result = exec_lua [[ - vim.diagnostic.config({ - signs = true, - }) + it('sets and clears signs #26193 #26555', function() + do + local result = exec_lua [[ + vim.diagnostic.config({ + signs = true, + }) - local diagnostics = { - make_error('Error', 1, 1, 1, 2), - make_warning('Warning', 3, 3, 3, 3), - } + local diagnostics = { + make_error('Error', 1, 1, 1, 2), + make_warning('Warning', 3, 3, 3, 3), + } - vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics) + vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics) - local ns = vim.diagnostic.get_namespace(diagnostic_ns) - local sign_ns = ns.user_data.sign_ns + local ns = vim.diagnostic.get_namespace(diagnostic_ns) + local sign_ns = ns.user_data.sign_ns - local signs = vim.api.nvim_buf_get_extmarks(diagnostic_bufnr, sign_ns, 0, -1, {type ='sign', details = true}) - local result = {} - for _, s in ipairs(signs) do - result[#result + 1] = { lnum = s[2] + 1, name = s[4].sign_hl_group } - end - return result - ]] + local signs = vim.api.nvim_buf_get_extmarks(diagnostic_bufnr, sign_ns, 0, -1, {type ='sign', details = true}) + local result = {} + for _, s in ipairs(signs) do + result[#result + 1] = { lnum = s[2] + 1, name = s[4].sign_hl_group } + end + return result + ]] + + eq({2, 'DiagnosticSignError'}, {result[1].lnum, result[1].name}) + eq({4, 'DiagnosticSignWarn'}, {result[2].lnum, result[2].name}) + end - eq({2, 'DiagnosticSignError'}, {result[1].lnum, result[1].name}) - eq({4, 'DiagnosticSignWarn'}, {result[2].lnum, result[2].name}) + do + local result = exec_lua [[ + vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, {}) + + local ns = vim.diagnostic.get_namespace(diagnostic_ns) + local sign_ns = ns.user_data.sign_ns + + return vim.api.nvim_buf_get_extmarks(diagnostic_bufnr, sign_ns, 0, -1, {type ='sign', details = true}) + ]] + + eq({}, result) + end end) end) -- cgit From 3a4aa3fc58f87a295a075fe457bc78805eef7c4d Mon Sep 17 00:00:00 2001 From: Gregory Anders <8965202+gpanders@users.noreply.github.com> Date: Mon, 18 Dec 2023 11:04:44 -0600 Subject: refactor: soft-deprecate diagnostic signs configured with :sign-define (#26618) Diagnostic signs should now be configured with vim.diagnostic.config(), but "legacy" sign definitions should go through the standard deprecation process to minimize the impact from breaking changes. --- test/functional/lua/diagnostic_spec.lua | 55 +++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'test/functional/lua/diagnostic_spec.lua') diff --git a/test/functional/lua/diagnostic_spec.lua b/test/functional/lua/diagnostic_spec.lua index 76963cc69e..688118a085 100644 --- a/test/functional/lua/diagnostic_spec.lua +++ b/test/functional/lua/diagnostic_spec.lua @@ -1537,6 +1537,61 @@ end) eq({}, result) end end) + + it('respects legacy signs placed with :sign define or sign_define #26618', function() + -- Legacy signs for diagnostics were deprecated in 0.10 and will be removed in 0.12 + eq(0, helpers.funcs.has('nvim-0.12')) + + helpers.command('sign define DiagnosticSignError text= texthl= linehl=ErrorMsg numhl=ErrorMsg') + helpers.command('sign define DiagnosticSignWarn text= texthl= linehl=WarningMsg numhl=WarningMsg') + helpers.command('sign define DiagnosticSignInfo text= texthl= linehl=Underlined numhl=Underlined') + helpers.command('sign define DiagnosticSignHint text= texthl= linehl=Underlined numhl=Underlined') + + local result = exec_lua [[ + vim.diagnostic.config({ + signs = true, + }) + + local diagnostics = { + make_error('Error', 1, 1, 1, 2), + make_warning('Warning', 3, 3, 3, 3), + } + + vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics) + + local ns = vim.diagnostic.get_namespace(diagnostic_ns) + local sign_ns = ns.user_data.sign_ns + + local signs = vim.api.nvim_buf_get_extmarks(diagnostic_bufnr, sign_ns, 0, -1, {type ='sign', details = true}) + local result = {} + for _, s in ipairs(signs) do + result[#result + 1] = { + lnum = s[2] + 1, + name = s[4].sign_hl_group, + text = s[4].sign_text or '', + numhl = s[4].number_hl_group, + linehl = s[4].line_hl_group, + } + end + return result + ]] + + eq({ + lnum = 2, + name = 'DiagnosticSignError', + text = '', + numhl = 'ErrorMsg', + linehl = 'ErrorMsg', + }, result[1]) + + eq({ + lnum = 4, + name = 'DiagnosticSignWarn', + text = '', + numhl = 'WarningMsg', + linehl = 'WarningMsg', + }, result[2]) + end) end) describe('open_float()', function() -- cgit From 4ee656e4f35766bef4e27c5afbfa8e3d8d74a76c Mon Sep 17 00:00:00 2001 From: Evgeni Chasnovski Date: Mon, 1 Jan 2024 23:03:50 +0200 Subject: feature(diagnostic): add `vim.diagnostic.count()` (#26807) feat(diagnostic): add `vim.diagnostic.count()` Problem: Getting diagnostic count based on the output of `vim.diagnostic.get()` might become costly as number of diagnostic entries grows. This is because it returns a copy of diagnostic cache entries (so as to not allow users to change them in place). Getting information about diagnostic count is frequently used in statusline, so it is important to be as fast as reasonbly possible. Solution: Add `vim.diagnostic.count()` which computes severity counts without making copies. --- test/functional/lua/diagnostic_spec.lua | 116 ++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) (limited to 'test/functional/lua/diagnostic_spec.lua') diff --git a/test/functional/lua/diagnostic_spec.lua b/test/functional/lua/diagnostic_spec.lua index 688118a085..d59ee02f01 100644 --- a/test/functional/lua/diagnostic_spec.lua +++ b/test/functional/lua/diagnostic_spec.lua @@ -930,6 +930,122 @@ end) end) end) + describe('count', function() + it('returns actually present severity counts', function() + eq( + exec_lua [[return { + [vim.diagnostic.severity.ERROR] = 4, + [vim.diagnostic.severity.WARN] = 3, + [vim.diagnostic.severity.INFO] = 2, + [vim.diagnostic.severity.HINT] = 1, + }]], + exec_lua [[ + vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { + make_error("Error 1", 1, 1, 1, 2), + make_error("Error 2", 1, 3, 1, 4), + make_error("Error 3", 1, 5, 1, 6), + make_error("Error 4", 1, 7, 1, 8), + make_warning("Warning 1", 2, 1, 2, 2), + make_warning("Warning 2", 2, 3, 2, 4), + make_warning("Warning 3", 2, 5, 2, 6), + make_info("Info 1", 3, 1, 3, 2), + make_info("Info 2", 3, 3, 3, 4), + make_hint("Hint 1", 4, 1, 4, 2), + }) + return vim.diagnostic.count(diagnostic_bufnr) + ]] + ) + eq( + exec_lua [[return { + [vim.diagnostic.severity.ERROR] = 2, + [vim.diagnostic.severity.INFO] = 1, + }]], + exec_lua [[ + vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { + make_error("Error 1", 1, 1, 1, 2), + make_error("Error 2", 1, 3, 1, 4), + make_info("Info 1", 3, 1, 3, 2), + }) + return vim.diagnostic.count(diagnostic_bufnr) + ]] + ) + end) + + it('returns only requested diagnostics count when severity range is supplied', function() + eq( + exec_lua [[return { + { [vim.diagnostic.severity.ERROR] = 1, [vim.diagnostic.severity.WARN] = 1 }, + { [vim.diagnostic.severity.WARN] = 1, [vim.diagnostic.severity.INFO] = 1, [vim.diagnostic.severity.HINT] = 1 }, + { [vim.diagnostic.severity.WARN] = 1, [vim.diagnostic.severity.INFO] = 1 }, + }]], + exec_lua [[ + vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { + make_error("Error 1", 1, 1, 1, 5), + make_warning("Warning on Server 1", 1, 1, 2, 3), + make_info("Ignored information", 1, 1, 2, 3), + make_hint("Here's a hint", 1, 1, 2, 3), + }) + + return { + vim.diagnostic.count(diagnostic_bufnr, { severity = {min=vim.diagnostic.severity.WARN} }), + vim.diagnostic.count(diagnostic_bufnr, { severity = {max=vim.diagnostic.severity.WARN} }), + vim.diagnostic.count(diagnostic_bufnr, { + severity = { + min=vim.diagnostic.severity.INFO, + max=vim.diagnostic.severity.WARN, + } + }), + } + ]] + ) + end) + + it('returns only requested diagnostics when severities are supplied', function() + eq( + exec_lua [[return { + { [vim.diagnostic.severity.WARN] = 1 }, + { [vim.diagnostic.severity.ERROR] = 1 }, + { [vim.diagnostic.severity.WARN] = 1, [vim.diagnostic.severity.INFO] = 1 }, + }]], + exec_lua [[ + vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { + make_error("Error 1", 1, 1, 1, 5), + make_warning("Warning on Server 1", 1, 1, 2, 3), + make_info("Ignored information", 1, 1, 2, 3), + make_hint("Here's a hint", 1, 1, 2, 3), + }) + + return { + vim.diagnostic.count(diagnostic_bufnr, { severity = {vim.diagnostic.severity.WARN} }), + vim.diagnostic.count(diagnostic_bufnr, { severity = {vim.diagnostic.severity.ERROR} }), + vim.diagnostic.count(diagnostic_bufnr, { + severity = { + vim.diagnostic.severity.INFO, + vim.diagnostic.severity.WARN, + } + }), + } + ]] + ) + end) + + it('allows filtering by line', function() + eq( + exec_lua [[return { [vim.diagnostic.severity.ERROR] = 1 }]], + exec_lua [[ + vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { + make_error("Error 1", 1, 1, 1, 5), + make_warning("Warning on Server 1", 1, 1, 2, 3), + make_info("Ignored information", 1, 1, 2, 3), + make_error("Error On Other Line", 2, 1, 1, 5), + }) + + return vim.diagnostic.count(diagnostic_bufnr, {lnum = 2}) + ]] + ) + end) + end) + describe('config()', function() it('works with global, namespace, and ephemeral options', function() eq(1, exec_lua [[ -- cgit From 04f2f864e270e772c6326cefdf24947f0130e492 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Wed, 3 Jan 2024 02:09:18 +0100 Subject: refactor: format test/* --- test/functional/lua/diagnostic_spec.lua | 847 ++++++++++++++++++++++---------- 1 file changed, 585 insertions(+), 262 deletions(-) (limited to 'test/functional/lua/diagnostic_spec.lua') diff --git a/test/functional/lua/diagnostic_spec.lua b/test/functional/lua/diagnostic_spec.lua index d59ee02f01..22ef66bc60 100644 --- a/test/functional/lua/diagnostic_spec.lua +++ b/test/functional/lua/diagnostic_spec.lua @@ -128,12 +128,20 @@ describe('vim.diagnostic', function() return vim.diagnostic.get() ]] eq(3, #result) - eq(2, exec_lua([[return #vim.tbl_filter(function(d) return d.bufnr == diagnostic_bufnr end, ...)]], result)) + eq( + 2, + exec_lua( + [[return #vim.tbl_filter(function(d) return d.bufnr == diagnostic_bufnr end, ...)]], + result + ) + ) eq('Diagnostic #1', result[1].message) end) it('removes diagnostics from the cache when a buffer is removed', function() - eq(2, exec_lua [[ + eq( + 2, + exec_lua [[ vim.api.nvim_win_set_buf(0, diagnostic_bufnr) local other_bufnr = vim.fn.bufadd('test | test') local lines = vim.api.nvim_buf_get_lines(diagnostic_bufnr, 0, -1, true) @@ -151,16 +159,23 @@ describe('vim.diagnostic', function() vim.opt_local.buflisted = true vim.cmd('bwipeout!') return #vim.diagnostic.get() - ]]) - eq(2, exec_lua [[ + ]] + ) + eq( + 2, + exec_lua [[ vim.api.nvim_set_current_buf(diagnostic_bufnr) vim.opt_local.buflisted = false return #vim.diagnostic.get() - ]]) - eq(0, exec_lua [[ + ]] + ) + eq( + 0, + exec_lua [[ vim.cmd('bwipeout!') return #vim.diagnostic.get() - ]]) + ]] + ) end) it('removes diagnostic from stale cache on reset', function() @@ -194,37 +209,48 @@ describe('vim.diagnostic', function() end) it('resolves buffer number 0 to the current buffer', function() - eq(2, exec_lua [[ + eq( + 2, + exec_lua [[ vim.api.nvim_set_current_buf(diagnostic_bufnr) vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { make_error('Diagnostic #1', 1, 1, 1, 1), make_error('Diagnostic #2', 2, 1, 2, 1), }) return #vim.diagnostic.get(0) - ]]) + ]] + ) end) it('saves and count a single error', function() - eq(1, exec_lua [[ + eq( + 1, + exec_lua [[ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { make_error('Diagnostic #1', 1, 1, 1, 1), }) return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns) - ]]) + ]] + ) end) it('saves and count multiple errors', function() - eq(2, exec_lua [[ + eq( + 2, + exec_lua [[ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { make_error('Diagnostic #1', 1, 1, 1, 1), make_error('Diagnostic #2', 2, 1, 2, 1), }) return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns) - ]]) + ]] + ) end) it('saves and count from multiple namespaces', function() - eq({1, 1, 2}, exec_lua [[ + eq( + { 1, 1, 2 }, + exec_lua [[ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { make_error('Diagnostic From Server 1', 1, 1, 1, 1), }) @@ -239,11 +265,14 @@ describe('vim.diagnostic', function() -- All namespaces count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR), } - ]]) + ]] + ) end) it('saves and count from multiple namespaces with respect to severity', function() - eq({3, 0, 3}, exec_lua [[ + eq( + { 3, 0, 3 }, + exec_lua [[ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { make_error('Diagnostic From Server 1:1', 1, 1, 1, 1), make_error('Diagnostic From Server 1:2', 2, 2, 2, 2), @@ -260,7 +289,8 @@ describe('vim.diagnostic', function() -- All namespaces count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR), } - ]]) + ]] + ) end) it('handles one namespace clearing highlights while the other still has highlights', function() @@ -269,8 +299,10 @@ describe('vim.diagnostic', function() -- 1 Warning (2) + 1 Warning (1) -- 2 highlights and 2 underlines (since error) -- 1 highlight + 1 underline - local all_highlights = {1, 1, 2, 4, 2} - eq(all_highlights, exec_lua [[ + local all_highlights = { 1, 1, 2, 4, 2 } + eq( + all_highlights, + exec_lua [[ local ns_1_diags = { make_error("Error 1", 1, 1, 1, 5), make_warning("Warning on Server 1", 2, 1, 2, 3), @@ -289,10 +321,13 @@ describe('vim.diagnostic', function() count_extmarks(diagnostic_bufnr, diagnostic_ns), count_extmarks(diagnostic_bufnr, other_ns), } - ]]) + ]] + ) -- Clear diagnostics from namespace 1, and make sure we have the right amount of stuff for namespace 2 - eq({1, 1, 2, 0, 2}, exec_lua [[ + eq( + { 1, 1, 2, 0, 2 }, + exec_lua [[ vim.diagnostic.disable(diagnostic_bufnr, diagnostic_ns) return { count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns), @@ -301,10 +336,13 @@ describe('vim.diagnostic', function() count_extmarks(diagnostic_bufnr, diagnostic_ns), count_extmarks(diagnostic_bufnr, other_ns), } - ]]) + ]] + ) -- Show diagnostics from namespace 1 again - eq(all_highlights, exec_lua([[ + eq( + all_highlights, + exec_lua([[ vim.diagnostic.enable(diagnostic_bufnr, diagnostic_ns) return { count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns), @@ -313,11 +351,14 @@ describe('vim.diagnostic', function() count_extmarks(diagnostic_bufnr, diagnostic_ns), count_extmarks(diagnostic_bufnr, other_ns), } - ]])) + ]]) + ) end) it('does not display diagnostics when disabled', function() - eq({0, 2}, exec_lua [[ + eq( + { 0, 2 }, + exec_lua [[ local ns_1_diags = { make_error("Error 1", 1, 1, 1, 5), make_warning("Warning on Server 1", 2, 1, 2, 3), @@ -335,9 +376,12 @@ describe('vim.diagnostic', function() count_extmarks(diagnostic_bufnr, diagnostic_ns), count_extmarks(diagnostic_bufnr, other_ns), } - ]]) + ]] + ) - eq({4, 0}, exec_lua [[ + eq( + { 4, 0 }, + exec_lua [[ vim.diagnostic.enable(diagnostic_bufnr, diagnostic_ns) vim.diagnostic.disable(diagnostic_bufnr, other_ns) @@ -345,7 +389,8 @@ describe('vim.diagnostic', function() count_extmarks(diagnostic_bufnr, diagnostic_ns), count_extmarks(diagnostic_bufnr, other_ns), } - ]]) + ]] + ) end) describe('show() and hide()', function() @@ -660,8 +705,10 @@ describe('vim.diagnostic', function() -- 1 Warning (2) + 1 Warning (1) -- 2 highlights and 2 underlines (since error) -- 1 highlight + 1 underline - local all_highlights = {1, 1, 2, 4, 2} - eq(all_highlights, exec_lua [[ + local all_highlights = { 1, 1, 2, 4, 2 } + eq( + all_highlights, + exec_lua [[ local ns_1_diags = { make_error("Error 1", 1, 1, 1, 5), make_warning("Warning on Server 1", 2, 1, 2, 3), @@ -680,13 +727,16 @@ describe('vim.diagnostic', function() count_extmarks(diagnostic_bufnr, diagnostic_ns), count_extmarks(diagnostic_bufnr, other_ns), } - ]]) + ]] + ) -- Reset diagnostics from namespace 1 exec_lua([[ vim.diagnostic.reset(diagnostic_ns) ]]) -- Make sure we have the right diagnostic count - eq({0, 1, 1, 0, 2} , exec_lua [[ + eq( + { 0, 1, 1, 0, 2 }, + exec_lua [[ local diagnostic_count = {} vim.wait(100, function () diagnostic_count = { count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns), @@ -696,13 +746,16 @@ describe('vim.diagnostic', function() count_extmarks(diagnostic_bufnr, other_ns), } end ) return diagnostic_count - ]]) + ]] + ) -- Reset diagnostics from namespace 2 exec_lua([[ vim.diagnostic.reset(other_ns) ]]) -- Make sure we have the right diagnostic count - eq({0, 0, 0, 0, 0}, exec_lua [[ + eq( + { 0, 0, 0, 0, 0 }, + exec_lua [[ local diagnostic_count = {} vim.wait(100, function () diagnostic_count = { count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns), @@ -712,8 +765,8 @@ describe('vim.diagnostic', function() count_extmarks(diagnostic_bufnr, other_ns), } end ) return diagnostic_count - ]]) - + ]] + ) end) it("doesn't error after bwipeout called on buffer", function() @@ -728,17 +781,22 @@ describe('vim.diagnostic', function() describe('get_next_pos()', function() it('can find the next pos with only one namespace', function() - eq({1, 1}, exec_lua [[ + eq( + { 1, 1 }, + exec_lua [[ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { make_error('Diagnostic #1', 1, 1, 1, 1), }) vim.api.nvim_win_set_buf(0, diagnostic_bufnr) return vim.diagnostic.get_next_pos() - ]]) + ]] + ) end) it('can find next pos with two errors', function() - eq({4, 4}, exec_lua [[ + eq( + { 4, 4 }, + exec_lua [[ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { make_error('Diagnostic #1', 1, 1, 1, 1), make_error('Diagnostic #2', 4, 4, 4, 4), @@ -746,44 +804,56 @@ describe('vim.diagnostic', function() vim.api.nvim_win_set_buf(0, diagnostic_bufnr) vim.api.nvim_win_set_cursor(0, {3, 1}) return vim.diagnostic.get_next_pos { namespace = diagnostic_ns } - ]]) + ]] + ) end) it('can cycle when position is past error', function() - eq({1, 1}, exec_lua [[ + eq( + { 1, 1 }, + exec_lua [[ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { make_error('Diagnostic #1', 1, 1, 1, 1), }) vim.api.nvim_win_set_buf(0, diagnostic_bufnr) vim.api.nvim_win_set_cursor(0, {3, 1}) return vim.diagnostic.get_next_pos { namespace = diagnostic_ns } - ]]) + ]] + ) end) it('will not cycle when wrap is off', function() - eq(false, exec_lua [[ + eq( + false, + exec_lua [[ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { make_error('Diagnostic #1', 1, 1, 1, 1), }) vim.api.nvim_win_set_buf(0, diagnostic_bufnr) vim.api.nvim_win_set_cursor(0, {3, 1}) return vim.diagnostic.get_next_pos { namespace = diagnostic_ns, wrap = false } - ]]) + ]] + ) end) it('can cycle even from the last line', function() - eq({4, 4}, exec_lua [[ + eq( + { 4, 4 }, + exec_lua [[ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { make_error('Diagnostic #2', 4, 4, 4, 4), }) vim.api.nvim_win_set_buf(0, diagnostic_bufnr) vim.api.nvim_win_set_cursor(0, {vim.api.nvim_buf_line_count(0), 1}) return vim.diagnostic.get_prev_pos { namespace = diagnostic_ns } - ]]) + ]] + ) end) it('works with diagnostics past the end of the line #16349', function() - eq({4, 0}, exec_lua [[ + eq( + { 4, 0 }, + exec_lua [[ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { make_error('Diagnostic #1', 3, 9001, 3, 9001), make_error('Diagnostic #2', 4, 0, 4, 0), @@ -792,11 +862,14 @@ describe('vim.diagnostic', function() vim.api.nvim_win_set_cursor(0, {1, 1}) vim.diagnostic.goto_next { float = false } return vim.diagnostic.get_next_pos { namespace = diagnostic_ns } - ]]) + ]] + ) end) it('works with diagnostics before the start of the line', function() - eq({4, 0}, exec_lua [[ + eq( + { 4, 0 }, + exec_lua [[ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { make_error('Diagnostic #1', 3, 9001, 3, 9001), make_error('Diagnostic #2', 4, -1, 4, -1), @@ -805,24 +878,30 @@ describe('vim.diagnostic', function() vim.api.nvim_win_set_cursor(0, {1, 1}) vim.diagnostic.goto_next { float = false } return vim.diagnostic.get_next_pos { namespace = diagnostic_ns } - ]]) -end) + ]] + ) + end) end) describe('get_prev_pos()', function() it('can find the prev pos with only one namespace', function() - eq({1, 1}, exec_lua [[ + eq( + { 1, 1 }, + exec_lua [[ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { make_error('Diagnostic #1', 1, 1, 1, 1), }) vim.api.nvim_win_set_buf(0, diagnostic_bufnr) vim.api.nvim_win_set_cursor(0, {3, 1}) return vim.diagnostic.get_prev_pos() - ]]) + ]] + ) end) it('can find prev pos with two errors', function() - eq({1, 1}, exec_lua [[ + eq( + { 1, 1 }, + exec_lua [[ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { make_error('Diagnostic #1', 1, 1, 1, 1), make_error('Diagnostic #2', 4, 4, 4, 4), @@ -830,29 +909,36 @@ end) vim.api.nvim_win_set_buf(0, diagnostic_bufnr) vim.api.nvim_win_set_cursor(0, {3, 1}) return vim.diagnostic.get_prev_pos { namespace = diagnostic_ns } - ]]) + ]] + ) end) it('can cycle when position is past error', function() - eq({4, 4}, exec_lua [[ + eq( + { 4, 4 }, + exec_lua [[ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { make_error('Diagnostic #2', 4, 4, 4, 4), }) vim.api.nvim_win_set_buf(0, diagnostic_bufnr) vim.api.nvim_win_set_cursor(0, {3, 1}) return vim.diagnostic.get_prev_pos { namespace = diagnostic_ns } - ]]) + ]] + ) end) it('respects wrap parameter', function() - eq(false, exec_lua [[ + eq( + false, + exec_lua [[ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { make_error('Diagnostic #2', 4, 4, 4, 4), }) vim.api.nvim_win_set_buf(0, diagnostic_bufnr) vim.api.nvim_win_set_cursor(0, {3, 1}) return vim.diagnostic.get_prev_pos { namespace = diagnostic_ns, wrap = false} - ]]) + ]] + ) end) end) @@ -862,18 +948,23 @@ end) end) it('returns all diagnostics when no severity is supplied', function() - eq(2, exec_lua [[ + eq( + 2, + exec_lua [[ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { make_error("Error 1", 1, 1, 1, 5), make_warning("Warning on Server 1", 1, 1, 2, 3), }) return #vim.diagnostic.get(diagnostic_bufnr) - ]]) + ]] + ) end) it('returns only requested diagnostics when severity range is supplied', function() - eq({2, 3, 2}, exec_lua [[ + eq( + { 2, 3, 2 }, + exec_lua [[ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { make_error("Error 1", 1, 1, 1, 5), make_warning("Warning on Server 1", 1, 1, 2, 3), @@ -891,11 +982,14 @@ end) } }), } - ]]) + ]] + ) end) it('returns only requested diagnostics when severities are supplied', function() - eq({1, 1, 2}, exec_lua [[ + eq( + { 1, 1, 2 }, + exec_lua [[ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { make_error("Error 1", 1, 1, 1, 5), make_warning("Warning on Server 1", 1, 1, 2, 3), @@ -913,11 +1007,14 @@ end) } }), } - ]]) + ]] + ) end) it('allows filtering by line', function() - eq(1, exec_lua [[ + eq( + 1, + exec_lua [[ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { make_error("Error 1", 1, 1, 1, 5), make_warning("Warning on Server 1", 1, 1, 2, 3), @@ -926,7 +1023,8 @@ end) }) return #vim.diagnostic.get(diagnostic_bufnr, {lnum = 2}) - ]]) + ]] + ) end) end) @@ -1048,7 +1146,9 @@ end) describe('config()', function() it('works with global, namespace, and ephemeral options', function() - eq(1, exec_lua [[ + eq( + 1, + exec_lua [[ vim.diagnostic.config({ virtual_text = false, }) @@ -1063,9 +1163,12 @@ end) }) return count_extmarks(diagnostic_bufnr, diagnostic_ns) - ]]) + ]] + ) - eq(1, exec_lua [[ + eq( + 1, + exec_lua [[ vim.diagnostic.config({ virtual_text = false, }) @@ -1080,9 +1183,12 @@ end) }, {virtual_text = true}) return count_extmarks(diagnostic_bufnr, diagnostic_ns) - ]]) + ]] + ) - eq(0, exec_lua [[ + eq( + 0, + exec_lua [[ vim.diagnostic.config({ virtual_text = false, }) @@ -1097,9 +1203,12 @@ end) }, {virtual_text = true}) return count_extmarks(diagnostic_bufnr, diagnostic_ns) - ]]) + ]] + ) - eq(1, exec_lua [[ + eq( + 1, + exec_lua [[ vim.diagnostic.config({ virtual_text = false, }) @@ -1116,7 +1225,8 @@ end) }) return count_extmarks(diagnostic_bufnr, diagnostic_ns) - ]]) + ]] + ) end) it('can use functions for config values', function() @@ -1129,7 +1239,10 @@ end) }) ]] - eq(1, exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]]) + eq( + 1, + exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]] + ) eq(2, exec_lua [[return count_extmarks(diagnostic_bufnr, diagnostic_ns)]]) -- Now, don't enable virtual text. @@ -1140,13 +1253,17 @@ end) }, diagnostic_ns) ]] - eq(1, exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]]) + eq( + 1, + exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]] + ) eq(1, exec_lua [[return count_extmarks(diagnostic_bufnr, diagnostic_ns)]]) end) it('allows filtering by severity', function() local get_extmark_count_with_severity = function(min_severity) - return exec_lua([[ + return exec_lua( + [[ vim.diagnostic.config({ underline = false, virtual_text = { @@ -1159,15 +1276,17 @@ end) }) return count_extmarks(diagnostic_bufnr, diagnostic_ns) - ]], min_severity) + ]], + min_severity + ) end -- No messages with Error or higher - eq(0, get_extmark_count_with_severity("ERROR")) + eq(0, get_extmark_count_with_severity('ERROR')) -- But now we don't filter it - eq(1, get_extmark_count_with_severity("WARN")) - eq(1, get_extmark_count_with_severity("HINT")) + eq(1, get_extmark_count_with_severity('WARN')) + eq(1, get_extmark_count_with_severity('HINT')) end) it('allows sorting by severity', function() @@ -1219,16 +1338,16 @@ end) -- Virt texts are defined lowest priority to highest, signs from -- highest to lowest - eq({'Warn', 'Error', 'Info'}, result[1]) - eq({'Info', 'Error', 'Warn'}, result[2]) + eq({ 'Warn', 'Error', 'Info' }, result[1]) + eq({ 'Info', 'Error', 'Warn' }, result[2]) result = exec_lua [[return get_virt_text_and_signs(true)]] - eq({'Info', 'Warn', 'Error'}, result[1]) - eq({'Error', 'Warn', 'Info'}, result[2]) + eq({ 'Info', 'Warn', 'Error' }, result[1]) + eq({ 'Error', 'Warn', 'Info' }, result[2]) result = exec_lua [[return get_virt_text_and_signs({ reverse = true })]] - eq({'Error', 'Warn', 'Info'}, result[1]) - eq({'Info', 'Warn', 'Error'}, result[2]) + eq({ 'Error', 'Warn', 'Info' }, result[1]) + eq({ 'Info', 'Warn', 'Error' }, result[2]) end) it('can show diagnostic sources in virtual text', function() @@ -1311,8 +1430,8 @@ end) local extmarks = get_virt_text_extmarks(diagnostic_ns) return {extmarks[1][4].virt_text, extmarks[2][4].virt_text} ]] - eq(" 👀 Warning", result[1][3][1]) - eq(" 🔥 Error", result[2][3][1]) + eq(' 👀 Warning', result[1][3][1]) + eq(' 🔥 Error', result[2][3][1]) end) it('includes source for formatted diagnostics', function() @@ -1339,12 +1458,14 @@ end) local extmarks = get_virt_text_extmarks(diagnostic_ns) return {extmarks[1][4].virt_text, extmarks[2][4].virt_text} ]] - eq(" some_linter: 👀 Warning", result[1][3][1]) - eq(" another_linter: 🔥 Error", result[2][3][1]) + eq(' some_linter: 👀 Warning', result[1][3][1]) + eq(' another_linter: 🔥 Error', result[2][3][1]) end) it('can add a prefix to virtual text', function() - eq('E Some error', exec_lua [[ + eq( + 'E Some error', + exec_lua [[ local diagnostics = { make_error('Some error', 0, 0, 0, 0), } @@ -1361,9 +1482,12 @@ end) local prefix = extmarks[1][4].virt_text[2][1] local message = extmarks[1][4].virt_text[3][1] return prefix .. message - ]]) + ]] + ) - eq('[(1/1) err-code] Some error', exec_lua [[ + eq( + '[(1/1) err-code] Some error', + exec_lua [[ local diagnostics = { make_error('Some error', 0, 0, 0, 0, nil, 'err-code'), } @@ -1380,11 +1504,14 @@ end) local prefix = extmarks[1][4].virt_text[2][1] local message = extmarks[1][4].virt_text[3][1] return prefix .. message - ]]) + ]] + ) end) it('can add a suffix to virtual text', function() - eq(' Some error ✘', exec_lua [[ + eq( + ' Some error ✘', + exec_lua [[ local diagnostics = { make_error('Some error', 0, 0, 0, 0), } @@ -1400,9 +1527,12 @@ end) local extmarks = get_virt_text_extmarks(diagnostic_ns) local virt_text = extmarks[1][4].virt_text[3][1] return virt_text - ]]) + ]] + ) - eq(' Some error [err-code]', exec_lua [[ + eq( + ' Some error [err-code]', + exec_lua [[ local diagnostics = { make_error('Some error', 0, 0, 0, 0, nil, 'err-code'), } @@ -1418,20 +1548,23 @@ end) local extmarks = get_virt_text_extmarks(diagnostic_ns) local virt_text = extmarks[1][4].virt_text[3][1] return virt_text - ]]) + ]] + ) end) end) describe('set()', function() it('validates its arguments', function() - matches("expected a list of diagnostics", - pcall_err(exec_lua, [[vim.diagnostic.set(1, 0, {lnum = 1, col = 2})]])) + matches( + 'expected a list of diagnostics', + pcall_err(exec_lua, [[vim.diagnostic.set(1, 0, {lnum = 1, col = 2})]]) + ) end) it('can perform updates after insert_leave', function() exec_lua [[vim.api.nvim_set_current_buf(diagnostic_bufnr)]] - nvim("input", "o") - eq({mode='i', blocking=false}, nvim("get_mode")) + nvim('input', 'o') + eq({ mode = 'i', blocking = false }, nvim('get_mode')) -- Save the diagnostics exec_lua [[ @@ -1444,21 +1577,27 @@ end) ]] -- No diagnostics displayed yet. - eq({mode='i', blocking=false}, nvim("get_mode")) - eq(1, exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]]) + eq({ mode = 'i', blocking = false }, nvim('get_mode')) + eq( + 1, + exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]] + ) eq(0, exec_lua [[return count_extmarks(diagnostic_bufnr, diagnostic_ns)]]) - nvim("input", "") - eq({mode='n', blocking=false}, nvim("get_mode")) + nvim('input', '') + eq({ mode = 'n', blocking = false }, nvim('get_mode')) - eq(1, exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]]) + eq( + 1, + exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]] + ) eq(2, exec_lua [[return count_extmarks(diagnostic_bufnr, diagnostic_ns)]]) end) it('does not perform updates when not needed', function() exec_lua [[vim.api.nvim_set_current_buf(diagnostic_bufnr)]] - nvim("input", "o") - eq({mode='i', blocking=false}, nvim("get_mode")) + nvim('input', 'o') + eq({ mode = 'i', blocking = false }, nvim('get_mode')) -- Save the diagnostics exec_lua [[ @@ -1480,24 +1619,30 @@ end) ]] -- No diagnostics displayed yet. - eq({mode='i', blocking=false}, nvim("get_mode")) - eq(1, exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]]) + eq({ mode = 'i', blocking = false }, nvim('get_mode')) + eq( + 1, + exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]] + ) eq(0, exec_lua [[return count_extmarks(diagnostic_bufnr, diagnostic_ns)]]) eq(0, exec_lua [[return DisplayCount]]) - nvim("input", "") - eq({mode='n', blocking=false}, nvim("get_mode")) + nvim('input', '') + eq({ mode = 'n', blocking = false }, nvim('get_mode')) - eq(1, exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]]) + eq( + 1, + exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]] + ) eq(2, exec_lua [[return count_extmarks(diagnostic_bufnr, diagnostic_ns)]]) eq(1, exec_lua [[return DisplayCount]]) -- Go in and out of insert mode one more time. - nvim("input", "o") - eq({mode='i', blocking=false}, nvim("get_mode")) + nvim('input', 'o') + eq({ mode = 'i', blocking = false }, nvim('get_mode')) - nvim("input", "") - eq({mode='n', blocking=false}, nvim("get_mode")) + nvim('input', '') + eq({ mode = 'n', blocking = false }, nvim('get_mode')) -- Should not have set the virtual text again. eq(1, exec_lua [[return DisplayCount]]) @@ -1505,8 +1650,8 @@ end) it('never sets virtual text, in combination with insert leave', function() exec_lua [[vim.api.nvim_set_current_buf(diagnostic_bufnr)]] - nvim("input", "o") - eq({mode='i', blocking=false}, nvim("get_mode")) + nvim('input', 'o') + eq({ mode = 'i', blocking = false }, nvim('get_mode')) -- Save the diagnostics exec_lua [[ @@ -1529,24 +1674,30 @@ end) ]] -- No diagnostics displayed yet. - eq({mode='i', blocking=false}, nvim("get_mode")) - eq(1, exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]]) + eq({ mode = 'i', blocking = false }, nvim('get_mode')) + eq( + 1, + exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]] + ) eq(0, exec_lua [[return count_extmarks(diagnostic_bufnr, diagnostic_ns)]]) eq(0, exec_lua [[return DisplayCount]]) - nvim("input", "") - eq({mode='n', blocking=false}, nvim("get_mode")) + nvim('input', '') + eq({ mode = 'n', blocking = false }, nvim('get_mode')) - eq(1, exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]]) + eq( + 1, + exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]] + ) eq(1, exec_lua [[return count_extmarks(diagnostic_bufnr, diagnostic_ns)]]) eq(0, exec_lua [[return DisplayCount]]) -- Go in and out of insert mode one more time. - nvim("input", "o") - eq({mode='i', blocking=false}, nvim("get_mode")) + nvim('input', 'o') + eq({ mode = 'i', blocking = false }, nvim('get_mode')) - nvim("input", "") - eq({mode='n', blocking=false}, nvim("get_mode")) + nvim('input', '') + eq({ mode = 'n', blocking = false }, nvim('get_mode')) -- Should not have set the virtual text still. eq(0, exec_lua [[return DisplayCount]]) @@ -1554,8 +1705,8 @@ end) it('can perform updates while in insert mode, if desired', function() exec_lua [[vim.api.nvim_set_current_buf(diagnostic_bufnr)]] - nvim("input", "o") - eq({mode='i', blocking=false}, nvim("get_mode")) + nvim('input', 'o') + eq({ mode = 'i', blocking = false }, nvim('get_mode')) -- Save the diagnostics exec_lua [[ @@ -1569,46 +1720,64 @@ end) ]] -- Diagnostics are displayed, because the user wanted them that way! - eq({mode='i', blocking=false}, nvim("get_mode")) - eq(1, exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]]) + eq({ mode = 'i', blocking = false }, nvim('get_mode')) + eq( + 1, + exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]] + ) eq(2, exec_lua [[return count_extmarks(diagnostic_bufnr, diagnostic_ns)]]) - nvim("input", "") - eq({mode='n', blocking=false}, nvim("get_mode")) + nvim('input', '') + eq({ mode = 'n', blocking = false }, nvim('get_mode')) - eq(1, exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]]) + eq( + 1, + exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]] + ) eq(2, exec_lua [[return count_extmarks(diagnostic_bufnr, diagnostic_ns)]]) end) it('can set diagnostics without displaying them', function() - eq(0, exec_lua [[ + eq( + 0, + exec_lua [[ vim.diagnostic.disable(diagnostic_bufnr, diagnostic_ns) vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { make_error('Diagnostic From Server 1:1', 1, 1, 1, 1), }) return count_extmarks(diagnostic_bufnr, diagnostic_ns) - ]]) + ]] + ) - eq(2, exec_lua [[ + eq( + 2, + exec_lua [[ vim.diagnostic.enable(diagnostic_bufnr, diagnostic_ns) return count_extmarks(diagnostic_bufnr, diagnostic_ns) - ]]) + ]] + ) end) it('can set display options', function() - eq(0, exec_lua [[ + eq( + 0, + exec_lua [[ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { make_error('Diagnostic From Server 1:1', 1, 1, 1, 1), }, { virtual_text = false, underline = false }) return count_extmarks(diagnostic_bufnr, diagnostic_ns) - ]]) + ]] + ) - eq(1, exec_lua [[ + eq( + 1, + exec_lua [[ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { make_error('Diagnostic From Server 1:1', 1, 1, 1, 1), }, { virtual_text = true, underline = false }) return count_extmarks(diagnostic_bufnr, diagnostic_ns) - ]]) + ]] + ) end) it('sets and clears signs #26193 #26555', function() @@ -1636,8 +1805,8 @@ end) return result ]] - eq({2, 'DiagnosticSignError'}, {result[1].lnum, result[1].name}) - eq({4, 'DiagnosticSignWarn'}, {result[2].lnum, result[2].name}) + eq({ 2, 'DiagnosticSignError' }, { result[1].lnum, result[1].name }) + eq({ 4, 'DiagnosticSignWarn' }, { result[2].lnum, result[2].name }) end do @@ -1658,10 +1827,18 @@ end) -- Legacy signs for diagnostics were deprecated in 0.10 and will be removed in 0.12 eq(0, helpers.funcs.has('nvim-0.12')) - helpers.command('sign define DiagnosticSignError text= texthl= linehl=ErrorMsg numhl=ErrorMsg') - helpers.command('sign define DiagnosticSignWarn text= texthl= linehl=WarningMsg numhl=WarningMsg') - helpers.command('sign define DiagnosticSignInfo text= texthl= linehl=Underlined numhl=Underlined') - helpers.command('sign define DiagnosticSignHint text= texthl= linehl=Underlined numhl=Underlined') + helpers.command( + 'sign define DiagnosticSignError text= texthl= linehl=ErrorMsg numhl=ErrorMsg' + ) + helpers.command( + 'sign define DiagnosticSignWarn text= texthl= linehl=WarningMsg numhl=WarningMsg' + ) + helpers.command( + 'sign define DiagnosticSignInfo text= texthl= linehl=Underlined numhl=Underlined' + ) + helpers.command( + 'sign define DiagnosticSignHint text= texthl= linehl=Underlined numhl=Underlined' + ) local result = exec_lua [[ vim.diagnostic.config({ @@ -1712,7 +1889,9 @@ end) describe('open_float()', function() it('can display a header', function() - eq({'Diagnostics:', '1. Syntax error'}, exec_lua [[ + eq( + { 'Diagnostics:', '1. Syntax error' }, + exec_lua [[ local diagnostics = { make_error("Syntax error", 0, 1, 0, 3), } @@ -1722,9 +1901,12 @@ end) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return lines - ]]) + ]] + ) - eq({"We're no strangers to love...", '1. Syntax error'}, exec_lua [[ + eq( + { "We're no strangers to love...", '1. Syntax error' }, + exec_lua [[ local diagnostics = { make_error("Syntax error", 0, 1, 0, 3), } @@ -1734,9 +1916,12 @@ end) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return lines - ]]) + ]] + ) - eq({'You know the rules', '1. Syntax error'}, exec_lua [[ + eq( + { 'You know the rules', '1. Syntax error' }, + exec_lua [[ local diagnostics = { make_error("Syntax error", 0, 1, 0, 3), } @@ -1746,11 +1931,14 @@ end) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return lines - ]]) + ]] + ) end) it('can show diagnostics from the whole buffer', function() - eq({'1. Syntax error', '2. Some warning'}, exec_lua [[ + eq( + { '1. Syntax error', '2. Some warning' }, + exec_lua [[ local diagnostics = { make_error("Syntax error", 0, 1, 0, 3), make_warning("Some warning", 1, 1, 1, 3), @@ -1761,12 +1949,15 @@ end) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return lines - ]]) + ]] + ) end) it('can show diagnostics from a single line', function() -- Using cursor position - eq({'1. Some warning'}, exec_lua [[ + eq( + { '1. Some warning' }, + exec_lua [[ local diagnostics = { make_error("Syntax error", 0, 1, 0, 3), make_warning("Some warning", 1, 1, 1, 3), @@ -1778,10 +1969,13 @@ end) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return lines - ]]) + ]] + ) -- With specified position - eq({'1. Some warning'}, exec_lua [[ + eq( + { '1. Some warning' }, + exec_lua [[ local diagnostics = { make_error("Syntax error", 0, 1, 0, 3), make_warning("Some warning", 1, 1, 1, 3), @@ -1793,12 +1987,15 @@ end) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return lines - ]]) + ]] + ) end) it('can show diagnostics from a specific position', function() -- Using cursor position - eq({'Syntax error'}, exec_lua [[ + eq( + { 'Syntax error' }, + exec_lua [[ local diagnostics = { make_error("Syntax error", 1, 1, 1, 2), make_warning("Some warning", 1, 3, 1, 4), @@ -1810,10 +2007,13 @@ end) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return lines - ]]) + ]] + ) -- With specified position - eq({'Some warning'}, exec_lua [[ + eq( + { 'Some warning' }, + exec_lua [[ local diagnostics = { make_error("Syntax error", 1, 1, 1, 2), make_warning("Some warning", 1, 3, 1, 4), @@ -1825,10 +2025,13 @@ end) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return lines - ]]) + ]] + ) -- With column position past the end of the line. #16062 - eq({'Syntax error'}, exec_lua [[ + eq( + { 'Syntax error' }, + exec_lua [[ local first_line_len = #vim.api.nvim_buf_get_lines(diagnostic_bufnr, 0, 1, true)[1] local diagnostics = { make_error("Syntax error", 0, first_line_len + 1, 1, 0), @@ -1840,14 +2043,19 @@ end) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return lines - ]]) + ]] + ) end) - it('creates floating window and returns float bufnr and winnr if current line contains diagnostics', function() - -- Two lines: - -- Diagnostic: - -- 1. - eq(2, exec_lua [[ + it( + 'creates floating window and returns float bufnr and winnr if current line contains diagnostics', + function() + -- Two lines: + -- Diagnostic: + -- 1. + eq( + 2, + exec_lua [[ local diagnostics = { make_error("Syntax error", 0, 1, 0, 3), } @@ -1857,11 +2065,15 @@ end) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return #lines - ]]) - end) + ]] + ) + end + ) it('only reports diagnostics from the current buffer when bufnr is omitted #15710', function() - eq(2, exec_lua [[ + eq( + 2, + exec_lua [[ local other_bufnr = vim.api.nvim_create_buf(true, false) local buf_1_diagnostics = { make_error("Syntax error", 0, 1, 0, 3), @@ -1876,11 +2088,14 @@ end) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return #lines - ]]) + ]] + ) end) it('allows filtering by namespace', function() - eq(2, exec_lua [[ + eq( + 2, + exec_lua [[ local ns_1_diagnostics = { make_error("Syntax error", 0, 1, 0, 3), } @@ -1894,13 +2109,18 @@ end) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return #lines - ]]) + ]] + ) end) - it('creates floating window and returns float bufnr and winnr without header, if requested', function() - -- One line (since no header): - -- 1. - eq(1, exec_lua [[ + it( + 'creates floating window and returns float bufnr and winnr without header, if requested', + function() + -- One line (since no header): + -- 1. + eq( + 1, + exec_lua [[ local diagnostics = { make_error("Syntax error", 0, 1, 0, 3), } @@ -1910,11 +2130,15 @@ end) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return #lines - ]]) - end) + ]] + ) + end + ) it('clamps diagnostic line numbers within the valid range', function() - eq(1, exec_lua [[ + eq( + 1, + exec_lua [[ local diagnostics = { make_error("Syntax error", 6, 0, 6, 0), } @@ -1924,13 +2148,16 @@ end) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return #lines - ]]) + ]] + ) end) it('can show diagnostic source', function() exec_lua [[vim.api.nvim_win_set_buf(0, diagnostic_bufnr)]] - eq({"1. Syntax error"}, exec_lua [[ + eq( + { '1. Syntax error' }, + exec_lua [[ local diagnostics = { make_error("Syntax error", 0, 1, 0, 3, "source x"), } @@ -1942,9 +2169,12 @@ end) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return lines - ]]) + ]] + ) - eq({"1. source x: Syntax error"}, exec_lua [[ + eq( + { '1. source x: Syntax error' }, + exec_lua [[ local float_bufnr, winnr = vim.diagnostic.open_float(diagnostic_bufnr, { header = false, source = "always", @@ -1952,9 +2182,12 @@ end) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return lines - ]]) + ]] + ) - eq({"1. source x: Syntax error", "2. source y: Another error"}, exec_lua [[ + eq( + { '1. source x: Syntax error', '2. source y: Another error' }, + exec_lua [[ local diagnostics = { make_error("Syntax error", 0, 1, 0, 3, "source x"), make_error("Another error", 0, 1, 0, 3, "source y"), @@ -1967,13 +2200,16 @@ end) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return lines - ]]) + ]] + ) end) it('respects severity_sort', function() exec_lua [[vim.api.nvim_win_set_buf(0, diagnostic_bufnr)]] - eq({"1. Syntax error", "2. Info", "3. Error", "4. Warning"}, exec_lua [[ + eq( + { '1. Syntax error', '2. Info', '3. Error', '4. Warning' }, + exec_lua [[ local diagnostics = { make_error("Syntax error", 0, 1, 0, 3), make_info('Info', 0, 3, 0, 4), @@ -1989,28 +2225,36 @@ end) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return lines - ]]) + ]] + ) - eq({"1. Syntax error", "2. Error", "3. Warning", "4. Info"}, exec_lua [[ + eq( + { '1. Syntax error', '2. Error', '3. Warning', '4. Info' }, + exec_lua [[ vim.diagnostic.config({severity_sort = true}) local float_bufnr, winnr = vim.diagnostic.open_float(diagnostic_bufnr, { header = false }) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return lines - ]]) + ]] + ) - eq({"1. Info", "2. Warning", "3. Error", "4. Syntax error"}, exec_lua [[ + eq( + { '1. Info', '2. Warning', '3. Error', '4. Syntax error' }, + exec_lua [[ vim.diagnostic.config({severity_sort = { reverse = true } }) local float_bufnr, winnr = vim.diagnostic.open_float(diagnostic_bufnr, { header = false }) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return lines - ]]) + ]] + ) end) it('can filter by severity', function() local count_diagnostics_with_severity = function(min_severity, max_severity) - return exec_lua([[ + return exec_lua( + [[ local min_severity, max_severity = ... vim.diagnostic.config({ float = { @@ -2033,19 +2277,24 @@ end) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return #lines - ]], min_severity, max_severity) + ]], + min_severity, + max_severity + ) end - eq(2, count_diagnostics_with_severity("ERROR")) - eq(3, count_diagnostics_with_severity("WARN")) - eq(1, count_diagnostics_with_severity("WARN", "WARN")) - eq(4, count_diagnostics_with_severity("HINT")) - eq(0, count_diagnostics_with_severity("HINT", "HINT")) + eq(2, count_diagnostics_with_severity('ERROR')) + eq(3, count_diagnostics_with_severity('WARN')) + eq(1, count_diagnostics_with_severity('WARN', 'WARN')) + eq(4, count_diagnostics_with_severity('HINT')) + eq(0, count_diagnostics_with_severity('HINT', 'HINT')) end) it('can add a prefix to diagnostics', function() -- Default is to add a number - eq({'1. Syntax error', '2. Some warning'}, exec_lua [[ + eq( + { '1. Syntax error', '2. Some warning' }, + exec_lua [[ local diagnostics = { make_error("Syntax error", 0, 1, 0, 3), make_warning("Some warning", 1, 1, 1, 3), @@ -2056,9 +2305,12 @@ end) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return lines - ]]) + ]] + ) - eq({'Syntax error', 'Some warning'}, exec_lua [[ + eq( + { 'Syntax error', 'Some warning' }, + exec_lua [[ local diagnostics = { make_error("Syntax error", 0, 1, 0, 3), make_warning("Some warning", 1, 1, 1, 3), @@ -2069,9 +2321,12 @@ end) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return lines - ]]) + ]] + ) - eq({'1. Syntax error', '2. Some warning'}, exec_lua [[ + eq( + { '1. Syntax error', '2. Some warning' }, + exec_lua [[ local diagnostics = { make_error("Syntax error", 0, 1, 0, 3), make_warning("Some warning", 0, 1, 0, 3), @@ -2091,9 +2346,12 @@ end) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return lines - ]]) + ]] + ) - eq({'Syntax error'}, exec_lua [[ + eq( + { 'Syntax error' }, + exec_lua [[ local diagnostics = { make_error("Syntax error", 0, 1, 0, 3), } @@ -2112,15 +2370,20 @@ end) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return lines - ]]) + ]] + ) - eq(".../diagnostic.lua:0: prefix: expected string|table|function, got number", - pcall_err(exec_lua, [[ vim.diagnostic.open_float({ prefix = 42 }) ]])) + eq( + '.../diagnostic.lua:0: prefix: expected string|table|function, got number', + pcall_err(exec_lua, [[ vim.diagnostic.open_float({ prefix = 42 }) ]]) + ) end) it('can add a suffix to diagnostics', function() -- Default is to render the diagnostic error code - eq({'1. Syntax error [code-x]', '2. Some warning [code-y]'}, exec_lua [[ + eq( + { '1. Syntax error [code-x]', '2. Some warning [code-y]' }, + exec_lua [[ local diagnostics = { make_error("Syntax error", 0, 1, 0, 3, nil, "code-x"), make_warning("Some warning", 1, 1, 1, 3, nil, "code-y"), @@ -2131,9 +2394,12 @@ end) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return lines - ]]) + ]] + ) - eq({'1. Syntax error', '2. Some warning'}, exec_lua [[ + eq( + { '1. Syntax error', '2. Some warning' }, + exec_lua [[ local diagnostics = { make_error("Syntax error", 0, 1, 0, 3, nil, "code-x"), make_warning("Some warning", 1, 1, 1, 3, nil, "code-y"), @@ -2144,10 +2410,13 @@ end) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return lines - ]]) + ]] + ) -- Suffix is rendered on the last line of a multiline diagnostic - eq({'1. Syntax error', ' More context [code-x]'}, exec_lua [[ + eq( + { '1. Syntax error', ' More context [code-x]' }, + exec_lua [[ local diagnostics = { make_error("Syntax error\nMore context", 0, 1, 0, 3, nil, "code-x"), } @@ -2157,14 +2426,19 @@ end) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return lines - ]]) + ]] + ) - eq(".../diagnostic.lua:0: suffix: expected string|table|function, got number", - pcall_err(exec_lua, [[ vim.diagnostic.open_float({ suffix = 42 }) ]])) + eq( + '.../diagnostic.lua:0: suffix: expected string|table|function, got number', + pcall_err(exec_lua, [[ vim.diagnostic.open_float({ suffix = 42 }) ]]) + ) end) it('works with the old signature', function() - eq({'1. Syntax error'}, exec_lua [[ + eq( + { '1. Syntax error' }, + exec_lua [[ local diagnostics = { make_error("Syntax error", 0, 1, 0, 3), } @@ -2174,7 +2448,8 @@ end) local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return lines - ]]) + ]] + ) end) end) @@ -2219,55 +2494,76 @@ end) describe('match()', function() it('matches a string', function() - local msg = "ERROR: george.txt:19:84:Two plus two equals five" + local msg = 'ERROR: george.txt:19:84:Two plus two equals five' local diagnostic = { severity = exec_lua [[return vim.diagnostic.severity.ERROR]], lnum = 18, col = 83, end_lnum = 18, end_col = 83, - message = "Two plus two equals five", + message = 'Two plus two equals five', } - eq(diagnostic, exec_lua([[ + eq( + diagnostic, + exec_lua( + [[ return vim.diagnostic.match(..., "^(%w+): [^:]+:(%d+):(%d+):(.+)$", {"severity", "lnum", "col", "message"}) - ]], msg)) + ]], + msg + ) + ) end) it('returns nil if the pattern fails to match', function() - eq(NIL, exec_lua [[ + eq( + NIL, + exec_lua [[ local msg = "The answer to life, the universe, and everything is" return vim.diagnostic.match(msg, "This definitely will not match", {}) - ]]) + ]] + ) end) it('respects default values', function() - local msg = "anna.txt:1:Happy families are all alike" + local msg = 'anna.txt:1:Happy families are all alike' local diagnostic = { severity = exec_lua [[return vim.diagnostic.severity.INFO]], lnum = 0, col = 0, end_lnum = 0, end_col = 0, - message = "Happy families are all alike", + message = 'Happy families are all alike', } - eq(diagnostic, exec_lua([[ + eq( + diagnostic, + exec_lua( + [[ return vim.diagnostic.match(..., "^[^:]+:(%d+):(.+)$", {"lnum", "message"}, nil, {severity = vim.diagnostic.severity.INFO}) - ]], msg)) + ]], + msg + ) + ) end) it('accepts a severity map', function() - local msg = "46:FATAL:Et tu, Brute?" + local msg = '46:FATAL:Et tu, Brute?' local diagnostic = { severity = exec_lua [[return vim.diagnostic.severity.ERROR]], lnum = 45, col = 0, end_lnum = 45, end_col = 0, - message = "Et tu, Brute?", + message = 'Et tu, Brute?', } - eq(diagnostic, exec_lua([[ + eq( + diagnostic, + exec_lua( + [[ return vim.diagnostic.match(..., "^(%d+):(%w+):(.+)$", {"lnum", "severity", "message"}, {FATAL = vim.diagnostic.severity.ERROR}) - ]], msg)) + ]], + msg + ) + ) end) end) @@ -2299,12 +2595,20 @@ end) describe('handlers', function() it('checks that a new handler is a table', function() - matches([[.*handler: expected table, got string.*]], pcall_err(exec_lua, [[ vim.diagnostic.handlers.foo = "bar" ]])) - matches([[.*handler: expected table, got function.*]], pcall_err(exec_lua, [[ vim.diagnostic.handlers.foo = function() end ]])) + matches( + [[.*handler: expected table, got string.*]], + pcall_err(exec_lua, [[ vim.diagnostic.handlers.foo = "bar" ]]) + ) + matches( + [[.*handler: expected table, got function.*]], + pcall_err(exec_lua, [[ vim.diagnostic.handlers.foo = function() end ]]) + ) end) it('can add new handlers', function() - eq(true, exec_lua [[ + eq( + true, + exec_lua [[ local handler_called = false vim.diagnostic.handlers.test = { show = function(namespace, bufnr, diagnostics, opts) @@ -2321,11 +2625,14 @@ end) make_warning("Warning", 0, 0, 0, 0), }) return handler_called - ]]) + ]] + ) end) it('can disable handlers by setting the corresponding option to false', function() - eq(false, exec_lua [[ + eq( + false, + exec_lua [[ local handler_called = false vim.diagnostic.handlers.test = { show = function(namespace, bufnr, diagnostics, opts) @@ -2338,11 +2645,14 @@ end) make_warning("Warning", 0, 0, 0, 0), }) return handler_called - ]]) + ]] + ) end) - it('always calls a handler\'s hide function if defined', function() - eq({false, true}, exec_lua [[ + it("always calls a handler's hide function if defined", function() + eq( + { false, true }, + exec_lua [[ local hide_called = false local show_called = false vim.diagnostic.handlers.test = { @@ -2362,11 +2672,14 @@ end) }) vim.diagnostic.hide(diagnostic_ns, diagnostic_bufnr) return {show_called, hide_called} - ]]) + ]] + ) end) it('triggers the autocommand when diagnostics are set', function() - eq({true, true}, exec_lua [[ + eq( + { true, true }, + exec_lua [[ -- Set a different buffer as current to test that is being set properly in -- DiagnosticChanged callbacks local tmp = vim.api.nvim_create_buf(false, true) @@ -2386,11 +2699,14 @@ end) triggered[1] == diagnostic_bufnr, triggered[2] == 1, } - ]]) - end) + ]] + ) + end) it('triggers the autocommand when diagnostics are cleared', function() - eq(true, exec_lua [[ + eq( + true, + exec_lua [[ local tmp = vim.api.nvim_create_buf(false, true) vim.api.nvim_set_current_buf(tmp) vim.g.diagnostic_autocmd_triggered = 0 @@ -2398,11 +2714,14 @@ end) vim.api.nvim_buf_set_name(diagnostic_bufnr, "test | test") vim.diagnostic.reset(diagnostic_ns, diagnostic_bufnr) return vim.g.diagnostic_autocmd_triggered == diagnostic_bufnr - ]]) - end) + ]] + ) + end) - it("checks if diagnostics are disabled in a buffer", function() - eq({true, true, true , true}, exec_lua [[ + it('checks if diagnostics are disabled in a buffer', function() + eq( + { true, true, true, true }, + exec_lua [[ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { make_error('Diagnostic #1', 1, 1, 1, 1), }) @@ -2414,9 +2733,12 @@ end) vim.diagnostic.is_disabled(diagnostic_bufnr, diagnostic_ns), vim.diagnostic.is_disabled(_, diagnostic_ns), } - ]]) + ]] + ) - eq({false, false, false , false}, exec_lua [[ + eq( + { false, false, false, false }, + exec_lua [[ vim.diagnostic.enable() return { vim.diagnostic.is_disabled(), @@ -2424,7 +2746,8 @@ end) vim.diagnostic.is_disabled(diagnostic_bufnr, diagnostic_ns), vim.diagnostic.is_disabled(_, diagnostic_ns), } - ]]) + ]] + ) end) end) end) -- cgit From d33e1da9b7f7e886219cfdd20b9bbfaccdc43be9 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 12 Jan 2024 11:28:20 +0000 Subject: test: do not inject vim module into global helpers --- test/functional/lua/diagnostic_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/lua/diagnostic_spec.lua') diff --git a/test/functional/lua/diagnostic_spec.lua b/test/functional/lua/diagnostic_spec.lua index 22ef66bc60..de1c139344 100644 --- a/test/functional/lua/diagnostic_spec.lua +++ b/test/functional/lua/diagnostic_spec.lua @@ -1,6 +1,6 @@ local helpers = require('test.functional.helpers')(after_each) -local NIL = helpers.NIL +local NIL = vim.NIL local command = helpers.command local clear = helpers.clear local exec_lua = helpers.exec_lua -- cgit From 4f81f506f96f8b5bfcf00e952ceb492d3ce9dc6e Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 12 Jan 2024 13:11:28 +0000 Subject: test: normalise nvim bridge functions - remove helpers.cur*meths - remove helpers.nvim --- test/functional/lua/diagnostic_spec.lua | 58 ++++++++++++++++----------------- 1 file changed, 29 insertions(+), 29 deletions(-) (limited to 'test/functional/lua/diagnostic_spec.lua') diff --git a/test/functional/lua/diagnostic_spec.lua b/test/functional/lua/diagnostic_spec.lua index de1c139344..523e771266 100644 --- a/test/functional/lua/diagnostic_spec.lua +++ b/test/functional/lua/diagnostic_spec.lua @@ -5,8 +5,8 @@ local command = helpers.command local clear = helpers.clear local exec_lua = helpers.exec_lua local eq = helpers.eq -local nvim = helpers.nvim local matches = helpers.matches +local meths = helpers.meths local pcall_err = helpers.pcall_err describe('vim.diagnostic', function() @@ -1563,8 +1563,8 @@ describe('vim.diagnostic', function() it('can perform updates after insert_leave', function() exec_lua [[vim.api.nvim_set_current_buf(diagnostic_bufnr)]] - nvim('input', 'o') - eq({ mode = 'i', blocking = false }, nvim('get_mode')) + meths.nvim_input('o') + eq({ mode = 'i', blocking = false }, meths.nvim_get_mode()) -- Save the diagnostics exec_lua [[ @@ -1577,15 +1577,15 @@ describe('vim.diagnostic', function() ]] -- No diagnostics displayed yet. - eq({ mode = 'i', blocking = false }, nvim('get_mode')) + eq({ mode = 'i', blocking = false }, meths.nvim_get_mode()) eq( 1, exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]] ) eq(0, exec_lua [[return count_extmarks(diagnostic_bufnr, diagnostic_ns)]]) - nvim('input', '') - eq({ mode = 'n', blocking = false }, nvim('get_mode')) + meths.nvim_input('') + eq({ mode = 'n', blocking = false }, meths.nvim_get_mode()) eq( 1, @@ -1596,8 +1596,8 @@ describe('vim.diagnostic', function() it('does not perform updates when not needed', function() exec_lua [[vim.api.nvim_set_current_buf(diagnostic_bufnr)]] - nvim('input', 'o') - eq({ mode = 'i', blocking = false }, nvim('get_mode')) + meths.nvim_input('o') + eq({ mode = 'i', blocking = false }, meths.nvim_get_mode()) -- Save the diagnostics exec_lua [[ @@ -1619,7 +1619,7 @@ describe('vim.diagnostic', function() ]] -- No diagnostics displayed yet. - eq({ mode = 'i', blocking = false }, nvim('get_mode')) + eq({ mode = 'i', blocking = false }, meths.nvim_get_mode()) eq( 1, exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]] @@ -1627,8 +1627,8 @@ describe('vim.diagnostic', function() eq(0, exec_lua [[return count_extmarks(diagnostic_bufnr, diagnostic_ns)]]) eq(0, exec_lua [[return DisplayCount]]) - nvim('input', '') - eq({ mode = 'n', blocking = false }, nvim('get_mode')) + meths.nvim_input('') + eq({ mode = 'n', blocking = false }, meths.nvim_get_mode()) eq( 1, @@ -1638,11 +1638,11 @@ describe('vim.diagnostic', function() eq(1, exec_lua [[return DisplayCount]]) -- Go in and out of insert mode one more time. - nvim('input', 'o') - eq({ mode = 'i', blocking = false }, nvim('get_mode')) + meths.nvim_input('o') + eq({ mode = 'i', blocking = false }, meths.nvim_get_mode()) - nvim('input', '') - eq({ mode = 'n', blocking = false }, nvim('get_mode')) + meths.nvim_input('') + eq({ mode = 'n', blocking = false }, meths.nvim_get_mode()) -- Should not have set the virtual text again. eq(1, exec_lua [[return DisplayCount]]) @@ -1650,8 +1650,8 @@ describe('vim.diagnostic', function() it('never sets virtual text, in combination with insert leave', function() exec_lua [[vim.api.nvim_set_current_buf(diagnostic_bufnr)]] - nvim('input', 'o') - eq({ mode = 'i', blocking = false }, nvim('get_mode')) + meths.nvim_input('o') + eq({ mode = 'i', blocking = false }, meths.nvim_get_mode()) -- Save the diagnostics exec_lua [[ @@ -1674,7 +1674,7 @@ describe('vim.diagnostic', function() ]] -- No diagnostics displayed yet. - eq({ mode = 'i', blocking = false }, nvim('get_mode')) + eq({ mode = 'i', blocking = false }, meths.nvim_get_mode()) eq( 1, exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]] @@ -1682,8 +1682,8 @@ describe('vim.diagnostic', function() eq(0, exec_lua [[return count_extmarks(diagnostic_bufnr, diagnostic_ns)]]) eq(0, exec_lua [[return DisplayCount]]) - nvim('input', '') - eq({ mode = 'n', blocking = false }, nvim('get_mode')) + meths.nvim_input('') + eq({ mode = 'n', blocking = false }, meths.nvim_get_mode()) eq( 1, @@ -1693,11 +1693,11 @@ describe('vim.diagnostic', function() eq(0, exec_lua [[return DisplayCount]]) -- Go in and out of insert mode one more time. - nvim('input', 'o') - eq({ mode = 'i', blocking = false }, nvim('get_mode')) + meths.nvim_input('o') + eq({ mode = 'i', blocking = false }, meths.nvim_get_mode()) - nvim('input', '') - eq({ mode = 'n', blocking = false }, nvim('get_mode')) + meths.nvim_input('') + eq({ mode = 'n', blocking = false }, meths.nvim_get_mode()) -- Should not have set the virtual text still. eq(0, exec_lua [[return DisplayCount]]) @@ -1705,8 +1705,8 @@ describe('vim.diagnostic', function() it('can perform updates while in insert mode, if desired', function() exec_lua [[vim.api.nvim_set_current_buf(diagnostic_bufnr)]] - nvim('input', 'o') - eq({ mode = 'i', blocking = false }, nvim('get_mode')) + meths.nvim_input('o') + eq({ mode = 'i', blocking = false }, meths.nvim_get_mode()) -- Save the diagnostics exec_lua [[ @@ -1720,15 +1720,15 @@ describe('vim.diagnostic', function() ]] -- Diagnostics are displayed, because the user wanted them that way! - eq({ mode = 'i', blocking = false }, nvim('get_mode')) + eq({ mode = 'i', blocking = false }, meths.nvim_get_mode()) eq( 1, exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]] ) eq(2, exec_lua [[return count_extmarks(diagnostic_bufnr, diagnostic_ns)]]) - nvim('input', '') - eq({ mode = 'n', blocking = false }, nvim('get_mode')) + meths.nvim_input('') + eq({ mode = 'n', blocking = false }, meths.nvim_get_mode()) eq( 1, -- cgit From 795f896a5772d5e0795f86642bdf90c82efac45c Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 12 Jan 2024 17:59:57 +0000 Subject: test: rename (meths, funcs) -> (api, fn) --- test/functional/lua/diagnostic_spec.lua | 60 ++++++++++++++++----------------- 1 file changed, 30 insertions(+), 30 deletions(-) (limited to 'test/functional/lua/diagnostic_spec.lua') diff --git a/test/functional/lua/diagnostic_spec.lua b/test/functional/lua/diagnostic_spec.lua index 523e771266..5802925339 100644 --- a/test/functional/lua/diagnostic_spec.lua +++ b/test/functional/lua/diagnostic_spec.lua @@ -6,7 +6,7 @@ local clear = helpers.clear local exec_lua = helpers.exec_lua local eq = helpers.eq local matches = helpers.matches -local meths = helpers.meths +local api = helpers.api local pcall_err = helpers.pcall_err describe('vim.diagnostic', function() @@ -1563,8 +1563,8 @@ describe('vim.diagnostic', function() it('can perform updates after insert_leave', function() exec_lua [[vim.api.nvim_set_current_buf(diagnostic_bufnr)]] - meths.nvim_input('o') - eq({ mode = 'i', blocking = false }, meths.nvim_get_mode()) + api.nvim_input('o') + eq({ mode = 'i', blocking = false }, api.nvim_get_mode()) -- Save the diagnostics exec_lua [[ @@ -1577,15 +1577,15 @@ describe('vim.diagnostic', function() ]] -- No diagnostics displayed yet. - eq({ mode = 'i', blocking = false }, meths.nvim_get_mode()) + eq({ mode = 'i', blocking = false }, api.nvim_get_mode()) eq( 1, exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]] ) eq(0, exec_lua [[return count_extmarks(diagnostic_bufnr, diagnostic_ns)]]) - meths.nvim_input('') - eq({ mode = 'n', blocking = false }, meths.nvim_get_mode()) + api.nvim_input('') + eq({ mode = 'n', blocking = false }, api.nvim_get_mode()) eq( 1, @@ -1596,8 +1596,8 @@ describe('vim.diagnostic', function() it('does not perform updates when not needed', function() exec_lua [[vim.api.nvim_set_current_buf(diagnostic_bufnr)]] - meths.nvim_input('o') - eq({ mode = 'i', blocking = false }, meths.nvim_get_mode()) + api.nvim_input('o') + eq({ mode = 'i', blocking = false }, api.nvim_get_mode()) -- Save the diagnostics exec_lua [[ @@ -1619,7 +1619,7 @@ describe('vim.diagnostic', function() ]] -- No diagnostics displayed yet. - eq({ mode = 'i', blocking = false }, meths.nvim_get_mode()) + eq({ mode = 'i', blocking = false }, api.nvim_get_mode()) eq( 1, exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]] @@ -1627,8 +1627,8 @@ describe('vim.diagnostic', function() eq(0, exec_lua [[return count_extmarks(diagnostic_bufnr, diagnostic_ns)]]) eq(0, exec_lua [[return DisplayCount]]) - meths.nvim_input('') - eq({ mode = 'n', blocking = false }, meths.nvim_get_mode()) + api.nvim_input('') + eq({ mode = 'n', blocking = false }, api.nvim_get_mode()) eq( 1, @@ -1638,11 +1638,11 @@ describe('vim.diagnostic', function() eq(1, exec_lua [[return DisplayCount]]) -- Go in and out of insert mode one more time. - meths.nvim_input('o') - eq({ mode = 'i', blocking = false }, meths.nvim_get_mode()) + api.nvim_input('o') + eq({ mode = 'i', blocking = false }, api.nvim_get_mode()) - meths.nvim_input('') - eq({ mode = 'n', blocking = false }, meths.nvim_get_mode()) + api.nvim_input('') + eq({ mode = 'n', blocking = false }, api.nvim_get_mode()) -- Should not have set the virtual text again. eq(1, exec_lua [[return DisplayCount]]) @@ -1650,8 +1650,8 @@ describe('vim.diagnostic', function() it('never sets virtual text, in combination with insert leave', function() exec_lua [[vim.api.nvim_set_current_buf(diagnostic_bufnr)]] - meths.nvim_input('o') - eq({ mode = 'i', blocking = false }, meths.nvim_get_mode()) + api.nvim_input('o') + eq({ mode = 'i', blocking = false }, api.nvim_get_mode()) -- Save the diagnostics exec_lua [[ @@ -1674,7 +1674,7 @@ describe('vim.diagnostic', function() ]] -- No diagnostics displayed yet. - eq({ mode = 'i', blocking = false }, meths.nvim_get_mode()) + eq({ mode = 'i', blocking = false }, api.nvim_get_mode()) eq( 1, exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]] @@ -1682,8 +1682,8 @@ describe('vim.diagnostic', function() eq(0, exec_lua [[return count_extmarks(diagnostic_bufnr, diagnostic_ns)]]) eq(0, exec_lua [[return DisplayCount]]) - meths.nvim_input('') - eq({ mode = 'n', blocking = false }, meths.nvim_get_mode()) + api.nvim_input('') + eq({ mode = 'n', blocking = false }, api.nvim_get_mode()) eq( 1, @@ -1693,11 +1693,11 @@ describe('vim.diagnostic', function() eq(0, exec_lua [[return DisplayCount]]) -- Go in and out of insert mode one more time. - meths.nvim_input('o') - eq({ mode = 'i', blocking = false }, meths.nvim_get_mode()) + api.nvim_input('o') + eq({ mode = 'i', blocking = false }, api.nvim_get_mode()) - meths.nvim_input('') - eq({ mode = 'n', blocking = false }, meths.nvim_get_mode()) + api.nvim_input('') + eq({ mode = 'n', blocking = false }, api.nvim_get_mode()) -- Should not have set the virtual text still. eq(0, exec_lua [[return DisplayCount]]) @@ -1705,8 +1705,8 @@ describe('vim.diagnostic', function() it('can perform updates while in insert mode, if desired', function() exec_lua [[vim.api.nvim_set_current_buf(diagnostic_bufnr)]] - meths.nvim_input('o') - eq({ mode = 'i', blocking = false }, meths.nvim_get_mode()) + api.nvim_input('o') + eq({ mode = 'i', blocking = false }, api.nvim_get_mode()) -- Save the diagnostics exec_lua [[ @@ -1720,15 +1720,15 @@ describe('vim.diagnostic', function() ]] -- Diagnostics are displayed, because the user wanted them that way! - eq({ mode = 'i', blocking = false }, meths.nvim_get_mode()) + eq({ mode = 'i', blocking = false }, api.nvim_get_mode()) eq( 1, exec_lua [[return count_diagnostics(diagnostic_bufnr, vim.diagnostic.severity.ERROR, diagnostic_ns)]] ) eq(2, exec_lua [[return count_extmarks(diagnostic_bufnr, diagnostic_ns)]]) - meths.nvim_input('') - eq({ mode = 'n', blocking = false }, meths.nvim_get_mode()) + api.nvim_input('') + eq({ mode = 'n', blocking = false }, api.nvim_get_mode()) eq( 1, @@ -1825,7 +1825,7 @@ describe('vim.diagnostic', function() it('respects legacy signs placed with :sign define or sign_define #26618', function() -- Legacy signs for diagnostics were deprecated in 0.10 and will be removed in 0.12 - eq(0, helpers.funcs.has('nvim-0.12')) + eq(0, helpers.fn.has('nvim-0.12')) helpers.command( 'sign define DiagnosticSignError text= texthl= linehl=ErrorMsg numhl=ErrorMsg' -- cgit