refactor: add vim._resolve_bufnr

This commit is contained in:
Lewis Russell
2024-12-07 13:05:05 +00:00
committed by Lewis Russell
parent b52ffd0a59
commit 668d2569b4
13 changed files with 61 additions and 121 deletions

View File

@@ -192,9 +192,7 @@ 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 = api.nvim_get_current_buf()
end
bufnr = vim._resolve_bufnr(bufnr)
local function buf_lines()
local lines = {} --- @type table<integer,string>
@@ -1976,7 +1974,7 @@ function M.make_given_range_params(start_pos, end_pos, bufnr, position_encoding)
validate('start_pos', start_pos, 'table', true)
validate('end_pos', end_pos, 'table', true)
validate('position_encoding', position_encoding, 'string', true)
bufnr = bufnr or api.nvim_get_current_buf()
bufnr = vim._resolve_bufnr(bufnr)
if position_encoding == nil then
vim.notify_once(
'position_encoding param is required in vim.lsp.util.make_given_range_params. Defaulting to position encoding of the first client.',
@@ -2143,10 +2141,7 @@ end
---@param opts? vim.lsp.util._refresh.Opts Options table
function M._refresh(method, opts)
opts = opts or {}
local bufnr = opts.bufnr
if bufnr == nil or bufnr == 0 then
bufnr = api.nvim_get_current_buf()
end
local bufnr = vim._resolve_bufnr(opts.bufnr)
local clients = vim.lsp.get_clients({ bufnr = bufnr, method = method, id = opts.client_id })