From e44f88bbe73fd4844cb065dc2d96599bdd42ca8f Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sat, 8 Jan 2022 13:31:39 +0100 Subject: [PATCH] fix(lsp): resolve bufnr for get_lines (#16997) Closes https://github.com/neovim/neovim/issues/16985 * get_lines checks if buf_loaded using bufnr 0, which is typically used as a sentinel value, but here must be resolved to the true bufnr (cherry picked from commit 5ebb1951bc47cb9f2c934669dd4e453f3d3e0b81) Co-authored-by: Michael Lingelbach --- runtime/lua/vim/lsp/util.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua index ae667c4106..cb1f9f4d77 100644 --- a/runtime/lua/vim/lsp/util.lua +++ b/runtime/lua/vim/lsp/util.lua @@ -201,6 +201,11 @@ end local function get_lines(bufnr, rows) rows = type(rows) == "table" and rows or { rows } + -- This is needed for bufload and bufloaded + if bufnr == 0 then + bufnr = vim.api.nvim_get_current_buf() + end + ---@private local function buf_lines() local lines = {} @@ -1822,7 +1827,7 @@ function M.make_given_range_params(start_pos, end_pos, bufnr, offset_encoding) end_pos = {end_pos, 't', true}; offset_encoding = {offset_encoding, 's', true}; } - bufnr = bufnr or 0 + bufnr = bufnr or vim.api.nvim_get_current_buf() offset_encoding = offset_encoding or M._get_offset_encoding(bufnr) local A = list_extend({}, start_pos or api.nvim_buf_get_mark(bufnr, '<')) local B = list_extend({}, end_pos or api.nvim_buf_get_mark(bufnr, '>'))