diff options
author | Raphael <glephunter@gmail.com> | 2024-04-23 19:06:41 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-23 04:06:41 -0700 |
commit | ad76b050eb2cd03174c108b5ae6759b3c1ea8941 (patch) | |
tree | 460fb0e7ab07ea66a85dac0c6c509461b81d9042 /test/functional/lua/diagnostic_spec.lua | |
parent | aef120d1e94e83a367a631d6bc8ce0b4a64f9dbd (diff) | |
download | rneovim-ad76b050eb2cd03174c108b5ae6759b3c1ea8941.tar.gz rneovim-ad76b050eb2cd03174c108b5ae6759b3c1ea8941.tar.bz2 rneovim-ad76b050eb2cd03174c108b5ae6759b3c1ea8941.zip |
fix(diagnostic): open_float on multi-line diagnostics #28301
Problem: when diagnostic have a range of line, open_float not work.
Solution: filter diagnostic by line number range.
Diffstat (limited to 'test/functional/lua/diagnostic_spec.lua')
-rw-r--r-- | test/functional/lua/diagnostic_spec.lua | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/test/functional/lua/diagnostic_spec.lua b/test/functional/lua/diagnostic_spec.lua index 31358a2226..4f60a2255f 100644 --- a/test/functional/lua/diagnostic_spec.lua +++ b/test/functional/lua/diagnostic_spec.lua @@ -2506,6 +2506,47 @@ describe('vim.diagnostic', function() ]] ) end) + + it('works for multi-line diagnostics #21949', function() + -- open float failed non diagnostic lnum + eq( + vim.NIL, + exec_lua [[ + local diagnostics = { + make_error("Error in two lines lnum is 1 and end_lnum is 2", 1, 1, 2, 3), + } + local winids = {} + vim.api.nvim_win_set_buf(0, diagnostic_bufnr) + vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics) + local _, winnr = vim.diagnostic.open_float(0, { header = false }) + return winnr + ]] + ) + + -- can open a float window on lnum 1 + eq( + { '1. Error in two lines lnum is 1 and end_lnum is 2' }, + exec_lua [[ + vim.api.nvim_win_set_cursor(0, {2, 0}) + local float_bufnr, winnr = vim.diagnostic.open_float(0, { header = false }) + local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) + vim.api.nvim_win_close(winnr, true) + return lines + ]] + ) + + -- can open a float window on end_lnum 2 + eq( + { '1. Error in two lines lnum is 1 and end_lnum is 2' }, + exec_lua [[ + vim.api.nvim_win_set_cursor(0, {3, 0}) + local float_bufnr, winnr = vim.diagnostic.open_float(0, { 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) end) describe('setloclist()', function() |