From 226a6c3eaef2a7220841d3d5e69e1baf543b3d6f Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Thu, 30 Mar 2023 14:49:58 +0100 Subject: feat(diagnostic): add support for tags The LSP spec supports two tags that can be added to diagnostics: unnecessary and deprecated. Extend vim.diagnostic to be able to handle these. --- test/functional/lua/diagnostic_spec.lua | 2 ++ 1 file changed, 2 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 d364986ad7..7b4d68c9cd 100644 --- a/test/functional/lua/diagnostic_spec.lua +++ b/test/functional/lua/diagnostic_spec.lua @@ -86,6 +86,7 @@ describe('vim.diagnostic', function() it('creates highlight groups', function() command('runtime plugin/diagnostic.vim') eq({ + 'DiagnosticDeprecated', 'DiagnosticError', 'DiagnosticFloatingError', 'DiagnosticFloatingHint', @@ -105,6 +106,7 @@ describe('vim.diagnostic', function() 'DiagnosticUnderlineInfo', 'DiagnosticUnderlineOk', 'DiagnosticUnderlineWarn', + 'DiagnosticUnnecessary', 'DiagnosticVirtualTextError', 'DiagnosticVirtualTextHint', 'DiagnosticVirtualTextInfo', -- cgit From b2d10aa01da4cf9341f68969b22875afb4afabd9 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 7 Apr 2023 09:38:52 +0800 Subject: test(lua/diagnostic_spec): remove unnecessary after_each() There is already a call to clear() in before_each(), so after_each() isn't necessary. --- test/functional/lua/diagnostic_spec.lua | 4 ---- 1 file changed, 4 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 7b4d68c9cd..6b4ca5ac73 100644 --- a/test/functional/lua/diagnostic_spec.lua +++ b/test/functional/lua/diagnostic_spec.lua @@ -79,10 +79,6 @@ describe('vim.diagnostic', function() ]]) end) - after_each(function() - clear() - end) - it('creates highlight groups', function() command('runtime plugin/diagnostic.vim') eq({ -- cgit From 07b60efd8058bb515998f50048b511d50f9671f8 Mon Sep 17 00:00:00 2001 From: Isak Samsten Date: Mon, 17 Apr 2023 13:53:34 +0200 Subject: feat(diagnostic): specify diagnostic virtual text prefix as a function - vim.diagnostic.config() now accepts a function for the virtual_text.prefix option, which allows for rendering e.g., diagnostic severities differently. --- test/functional/lua/diagnostic_spec.lua | 60 +++++++++++++++++++++++++++------ 1 file changed, 50 insertions(+), 10 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 6b4ca5ac73..17b2d7da4f 100644 --- a/test/functional/lua/diagnostic_spec.lua +++ b/test/functional/lua/diagnostic_spec.lua @@ -1042,7 +1042,7 @@ end) local virt_text = get_virt_text_extmarks(diagnostic_ns)[1][4].virt_text local virt_texts = {} - for i = 2, #virt_text do + for i = 2, #virt_text - 1 do table.insert(virt_texts, (string.gsub(virt_text[i][2], "DiagnosticVirtualText", ""))) end @@ -1086,7 +1086,7 @@ end) }) local extmarks = get_virt_text_extmarks(diagnostic_ns) - local virt_text = extmarks[1][4].virt_text[2][1] + local virt_text = extmarks[1][4].virt_text[3][1] return virt_text ]] eq(' source x: Some error', result) @@ -1101,7 +1101,7 @@ end) }, diagnostic_ns) local extmarks = get_virt_text_extmarks(diagnostic_ns) - local virt_text = extmarks[1][4].virt_text[2][1] + local virt_text = extmarks[1][4].virt_text[3][1] return virt_text ]] eq(' Some error', result) @@ -1121,7 +1121,7 @@ end) }) local extmarks = get_virt_text_extmarks(diagnostic_ns) - local virt_text = {extmarks[1][4].virt_text[2][1], extmarks[2][4].virt_text[2][1]} + local virt_text = {extmarks[1][4].virt_text[3][1], extmarks[2][4].virt_text[3][1]} return virt_text ]] eq(' source x: Some error', result[1]) @@ -1151,8 +1151,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][2][1]) - eq(" 🔥 Error", result[2][2][1]) + eq(" 👀 Warning", result[1][3][1]) + eq(" 🔥 Error", result[2][3][1]) end) it('includes source for formatted diagnostics', function() @@ -1179,8 +1179,48 @@ 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][2][1]) - eq(" another_linter: 🔥 Error", result[2][2][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 [[ + local diagnostics = { + make_error('Some error', 0, 0, 0, 0), + } + + vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics, { + underline = false, + virtual_text = { + prefix = 'E', + suffix = '', + } + }) + + local extmarks = get_virt_text_extmarks(diagnostic_ns) + local prefix = extmarks[1][4].virt_text[2][1] + local message = extmarks[1][4].virt_text[3][1] + return prefix .. message + ]]) + + eq('[err-code] Some error', exec_lua [[ + local diagnostics = { + make_error('Some error', 0, 0, 0, 0, nil, 'err-code'), + } + + vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics, { + underline = false, + virtual_text = { + prefix = function(diag) return string.format('[%s]', diag.code) end, + suffix = '', + } + }) + + local extmarks = get_virt_text_extmarks(diagnostic_ns) + 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() @@ -1198,7 +1238,7 @@ end) }) local extmarks = get_virt_text_extmarks(diagnostic_ns) - local virt_text = extmarks[1][4].virt_text[2][1] + local virt_text = extmarks[1][4].virt_text[3][1] return virt_text ]]) @@ -1216,7 +1256,7 @@ end) }) local extmarks = get_virt_text_extmarks(diagnostic_ns) - local virt_text = extmarks[1][4].virt_text[2][1] + local virt_text = extmarks[1][4].virt_text[3][1] return virt_text ]]) end) -- cgit From e7801775060e2d8f9f20572fac687f438e81caa0 Mon Sep 17 00:00:00 2001 From: Michael Strobel <71396679+Kibadda@users.noreply.github.com> Date: Wed, 16 Aug 2023 15:49:14 +0200 Subject: feat(diagnostic): filter diagnostics by specific severities (#24736) Allow users to filter diagnostics by specifying severities --- test/functional/lua/diagnostic_spec.lua | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 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 17b2d7da4f..27ba70f057 100644 --- a/test/functional/lua/diagnostic_spec.lua +++ b/test/functional/lua/diagnostic_spec.lua @@ -860,7 +860,7 @@ end) ]]) end) - it('returns only requested diagnostics when severity is supplied', function() + it('returns only requested diagnostics when severity range is supplied', function() eq({2, 3, 2}, exec_lua [[ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { make_error("Error 1", 1, 1, 1, 5), @@ -882,6 +882,28 @@ end) ]]) end) + it('returns only requested diagnostics when severities are supplied', function() + 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), + make_info("Ignored information", 1, 1, 2, 3), + make_hint("Here's a hint", 1, 1, 2, 3), + }) + + return { + #vim.diagnostic.get(diagnostic_bufnr, { severity = {vim.diagnostic.severity.WARN} }), + #vim.diagnostic.get(diagnostic_bufnr, { severity = {vim.diagnostic.severity.ERROR} }), + #vim.diagnostic.get(diagnostic_bufnr, { + severity = { + vim.diagnostic.severity.INFO, + vim.diagnostic.severity.WARN, + } + }), + } + ]]) + end) + it('allows filtering by line', function() eq(1, exec_lua [[ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { -- cgit From d27214331815324ea5762b5aa22996b9019085c6 Mon Sep 17 00:00:00 2001 From: Evgeni Chasnovski Date: Wed, 6 Sep 2023 20:54:18 +0300 Subject: fix(diagnostic): always return copies of diagnostic items (#25010) --- test/functional/lua/diagnostic_spec.lua | 12 ++++++++++++ 1 file changed, 12 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 27ba70f057..8deb2e0726 100644 --- a/test/functional/lua/diagnostic_spec.lua +++ b/test/functional/lua/diagnostic_spec.lua @@ -181,6 +181,18 @@ describe('vim.diagnostic', function() eq(0, #diagnostics) end) + it('always returns a copy of diagnostic tables', function() + local result = exec_lua [[ + vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { + make_error('Diagnostic #1', 1, 1, 1, 1), + }) + local diag = vim.diagnostic.get() + diag[1].col = 10000 + return vim.diagnostic.get()[1].col == 10000 + ]] + eq(result, false) + end) + it('resolves buffer number 0 to the current buffer', function() eq(2, exec_lua [[ vim.api.nvim_set_current_buf(diagnostic_bufnr) -- cgit From add1b10b79011d1af61419a63cc8ef4645f45bbf Mon Sep 17 00:00:00 2001 From: Jongwook Choi Date: Fri, 27 Oct 2023 09:17:46 -0400 Subject: fix(diagnostic): virtual_text prefix function should have index and total (#25801) The prefix option of the diagnostic virtual text can be a function, but previously it was only a function of diagnostic. This function should also have additional parameters index and total, more consistently and similarily as in the prefix function for `vim.diagnostic.open_float()`. These additional parameters will be useful when there are too many number of diagnostics in a single line. --- test/functional/lua/diagnostic_spec.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 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 8deb2e0726..f061fac50a 100644 --- a/test/functional/lua/diagnostic_spec.lua +++ b/test/functional/lua/diagnostic_spec.lua @@ -1237,7 +1237,7 @@ end) return prefix .. message ]]) - eq('[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'), } @@ -1245,7 +1245,7 @@ end) vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics, { underline = false, virtual_text = { - prefix = function(diag) return string.format('[%s]', diag.code) end, + prefix = function(diag, i, total) return string.format('[(%d/%d) %s]', i, total, diag.code) end, suffix = '', } }) -- cgit