aboutsummaryrefslogtreecommitdiff
path: root/test/functional/lua/diagnostic_spec.lua
diff options
context:
space:
mode:
authorGregory Anders <8965202+gpanders@users.noreply.github.com>2024-04-25 08:07:44 -0500
committerGitHub <noreply@github.com>2024-04-25 08:07:44 -0500
commitb13e63db1dbc1dbc7e23690653df1b7317660a2b (patch)
tree71d2f0076c20138b44d55dd2ba44d0c41e49b8d6 /test/functional/lua/diagnostic_spec.lua
parente0d92b9cc20b58179599f53dfa74ca821935a539 (diff)
downloadrneovim-b13e63db1dbc1dbc7e23690653df1b7317660a2b.tar.gz
rneovim-b13e63db1dbc1dbc7e23690653df1b7317660a2b.tar.bz2
rneovim-b13e63db1dbc1dbc7e23690653df1b7317660a2b.zip
feat(diagnostic): goto functions jump to highest severity (#28490)
When the "severity" option is nil, vim.diagnostic.goto_next() and vim.diagnostic.goto_prev() jump to the next diagnostic with the highest severity.
Diffstat (limited to 'test/functional/lua/diagnostic_spec.lua')
-rw-r--r--test/functional/lua/diagnostic_spec.lua141
1 files changed, 119 insertions, 22 deletions
diff --git a/test/functional/lua/diagnostic_spec.lua b/test/functional/lua/diagnostic_spec.lua
index f36a676ba9..534d78fd09 100644
--- a/test/functional/lua/diagnostic_spec.lua
+++ b/test/functional/lua/diagnostic_spec.lua
@@ -18,12 +18,12 @@ describe('vim.diagnostic', function()
exec_lua [[
require('vim.diagnostic')
- function make_diagnostic(msg, x1, y1, x2, y2, severity, source, code)
+ function make_diagnostic(msg, lnum, col, end_lnum, end_col, severity, source, code)
return {
- lnum = x1,
- col = y1,
- end_lnum = x2,
- end_col = y2,
+ lnum = lnum,
+ col = col,
+ end_lnum = end_lnum,
+ end_col = end_col,
message = msg,
severity = severity,
source = source,
@@ -31,20 +31,20 @@ describe('vim.diagnostic', function()
}
end
- function make_error(msg, x1, y1, x2, y2, source, code)
- return make_diagnostic(msg, x1, y1, x2, y2, vim.diagnostic.severity.ERROR, source, code)
+ function make_error(msg, lnum, col, end_lnum, end_col, source, code)
+ return make_diagnostic(msg, lnum, col, end_lnum, end_col, vim.diagnostic.severity.ERROR, source, code)
end
- function make_warning(msg, x1, y1, x2, y2, source, code)
- return make_diagnostic(msg, x1, y1, x2, y2, vim.diagnostic.severity.WARN, source, code)
+ function make_warning(msg, lnum, col, end_lnum, end_col, source, code)
+ return make_diagnostic(msg, lnum, col, end_lnum, end_col, vim.diagnostic.severity.WARN, source, code)
end
- function make_info(msg, x1, y1, x2, y2, source, code)
- return make_diagnostic(msg, x1, y1, x2, y2, vim.diagnostic.severity.INFO, source, code)
+ function make_info(msg, lnum, col, end_lnum, end_col, source, code)
+ return make_diagnostic(msg, lnum, col, end_lnum, end_col, vim.diagnostic.severity.INFO, source, code)
end
- function make_hint(msg, x1, y1, x2, y2, source, code)
- return make_diagnostic(msg, x1, y1, x2, y2, vim.diagnostic.severity.HINT, source, code)
+ function make_hint(msg, lnum, col, end_lnum, end_col, source, code)
+ return make_diagnostic(msg, lnum, col, end_lnum, end_col, vim.diagnostic.severity.HINT, source, code)
end
function count_diagnostics(bufnr, severity, namespace)
@@ -934,15 +934,112 @@ describe('vim.diagnostic', function()
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),
- })
- vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
- vim.api.nvim_win_set_cursor(0, {1, 1})
- vim.diagnostic.goto_next { float = false }
- return vim.diagnostic.get_next_pos { namespace = diagnostic_ns }
- ]]
+ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, {
+ make_error('Diagnostic #1', 3, 9001, 3, 9001),
+ make_error('Diagnostic #2', 4, -1, 4, -1),
+ })
+ vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
+ 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('jumps to diagnostic with highest severity', function()
+ exec_lua([[
+ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, {
+ make_info('Info', 1, 0, 1, 1),
+ make_error('Error', 2, 0, 2, 1),
+ make_warning('Warning', 3, 0, 3, 1),
+ make_error('Error', 4, 0, 4, 1),
+ })
+
+ vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
+ vim.api.nvim_win_set_cursor(0, {1, 0})
+ ]])
+
+ eq(
+ { 3, 0 },
+ exec_lua([[
+ vim.diagnostic.goto_next()
+ return vim.api.nvim_win_get_cursor(0)
+ ]])
+ )
+
+ eq(
+ { 5, 0 },
+ exec_lua([[
+ vim.diagnostic.goto_next()
+ return vim.api.nvim_win_get_cursor(0)
+ ]])
+ )
+
+ exec_lua([[
+ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, {
+ make_info('Info', 1, 0, 1, 1),
+ make_hint('Hint', 2, 0, 2, 1),
+ make_warning('Warning', 3, 0, 3, 1),
+ make_hint('Hint', 4, 0, 4, 1),
+ make_warning('Warning', 5, 0, 5, 1),
+ })
+
+ vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
+ vim.api.nvim_win_set_cursor(0, {1, 0})
+ ]])
+
+ eq(
+ { 4, 0 },
+ exec_lua([[
+ vim.diagnostic.goto_next()
+ return vim.api.nvim_win_get_cursor(0)
+ ]])
+ )
+
+ eq(
+ { 6, 0 },
+ exec_lua([[
+ vim.diagnostic.goto_next()
+ return vim.api.nvim_win_get_cursor(0)
+ ]])
+ )
+ end)
+
+ it('jumps to next diagnostic if severity is non-nil', function()
+ exec_lua([[
+ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, {
+ make_info('Info', 1, 0, 1, 1),
+ make_error('Error', 2, 0, 2, 1),
+ make_warning('Warning', 3, 0, 3, 1),
+ make_error('Error', 4, 0, 4, 1),
+ })
+
+ vim.api.nvim_win_set_buf(0, diagnostic_bufnr)
+ vim.api.nvim_win_set_cursor(0, {1, 0})
+ ]])
+
+ eq(
+ { 2, 0 },
+ exec_lua([[
+ vim.diagnostic.goto_next({ severity = { min = vim.diagnostic.severity.HINT } })
+ return vim.api.nvim_win_get_cursor(0)
+ ]])
+ )
+
+ eq(
+ { 3, 0 },
+ exec_lua([[
+ vim.diagnostic.goto_next({ severity = { min = vim.diagnostic.severity.HINT } })
+ return vim.api.nvim_win_get_cursor(0)
+ ]])
+ )
+
+ eq(
+ { 4, 0 },
+ exec_lua([[
+ vim.diagnostic.goto_next({ severity = { min = vim.diagnostic.severity.HINT } })
+ return vim.api.nvim_win_get_cursor(0)
+ ]])
)
end)
end)