diff options
author | Gregory Anders <8965202+gpanders@users.noreply.github.com> | 2021-11-22 09:22:08 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-22 09:22:08 -0700 |
commit | fd6df7481a88006fd60bc8980b4db1000ddeda27 (patch) | |
tree | a8ed1b6eaf9d593987d12749d86c5eec7e582762 | |
parent | e02d4732f2d523b2dc4bf436b28341f54ea89132 (diff) | |
download | rneovim-fd6df7481a88006fd60bc8980b4db1000ddeda27.tar.gz rneovim-fd6df7481a88006fd60bc8980b4db1000ddeda27.tar.bz2 rneovim-fd6df7481a88006fd60bc8980b4db1000ddeda27.zip |
fix(diagnostic): resolve buffer number in get() (#16407)
-rw-r--r-- | runtime/lua/vim/diagnostic.lua | 2 | ||||
-rw-r--r-- | test/functional/lua/diagnostic_spec.lua | 11 |
2 files changed, 13 insertions, 0 deletions
diff --git a/runtime/lua/vim/diagnostic.lua b/runtime/lua/vim/diagnostic.lua index c545808b70..74996faf3c 100644 --- a/runtime/lua/vim/diagnostic.lua +++ b/runtime/lua/vim/diagnostic.lua @@ -395,6 +395,7 @@ local function get_diagnostics(bufnr, opts, clamp) end end elseif namespace == nil then + bufnr = get_bufnr(bufnr) for iter_namespace in pairs(diagnostic_cache[bufnr]) do for _, diagnostic in pairs(diagnostic_cache[bufnr][iter_namespace]) do add(diagnostic) @@ -407,6 +408,7 @@ local function get_diagnostics(bufnr, opts, clamp) end end else + bufnr = get_bufnr(bufnr) for _, diagnostic in pairs(diagnostic_cache[bufnr][namespace] or {}) do add(diagnostic) end diff --git a/test/functional/lua/diagnostic_spec.lua b/test/functional/lua/diagnostic_spec.lua index 05745a5099..aacb8cf3ae 100644 --- a/test/functional/lua/diagnostic_spec.lua +++ b/test/functional/lua/diagnostic_spec.lua @@ -128,6 +128,17 @@ describe('vim.diagnostic', function() eq('Diagnostic #1', result[1].message) end) + it('resolves buffer number 0 to the current buffer', function() + 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 [[ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { |