Repository: neovim/neovim
File: runtime/lua/vim/lsp/util.lua (Lua)

Code before:
  for _, client in
    ipairs(clients or vim.lsp.get_clients({
      bufnr = bufnr,
      method = method,
    }))
  do
    for id, request in pairs(client.requests) do
      if
        (bufnr == nil or bufnr == request.bufnr)
        and (method == nil or method == request.method)
        and (type == nil or type == request.type)
      then
        client:cancel_request(id)
      end
    end
  end
end

---@class (private) vim.lsp.util._refresh.Opts
---@field bufnr integer? Buffer to refresh (default: 0)
---@field only_visible? boolean Whether to only refresh for the visible regions of the buffer (default: false)
---@field client_id? integer Client ID to refresh (default: all clients)
---@field handler? lsp.Handler

---@deprecated
---@private
--- Request updated LSP information for a buffer.
---
---@param method string LSP method to call
---@param opts? vim.lsp.util._refresh.Opts Options table
function M._refresh(method, opts)
  opts = opts or {}
  local bufnr = vim._resolve_bufnr(opts.bufnr)

  local clients = vim.lsp.get_clients({ bufnr = bufnr, method = method, id = opts.client_id })

  if #clients == 0 then
    return
  end

  local textDocument = M.make_text_document_params(bufnr)

  if opts.only_visible then
    for _, window in ipairs(api.nvim_list_wins()) do
      if api.nvim_win_get_buf(window) == bufnr then
        local first = vim.fn.line('w0', window)
        local last = vim.fn.line('w$', window)
        M._cancel_requests({
          bufnr = bufnr,
          clients = clients,
          method = method,

Review comment (suggestion):
It the function is already `@private` then I would skip the deprecation and just remove it entirely.

Code after:
---
---@param buf integer buffer number (0 for current)
---@param row integer 0-indexed line
---@param col integer 0-indexed byte offset in line
---@param offset_encoding? 'utf-8'|'utf-16'|'utf-32'
---                        defaults to `offset_encoding` of first client of `buf`
---@return integer `offset_encoding` index of the character in line {row} column {col} in buffer {buf}
function M.character_offset(buf, row, col, offset_encoding)
  local line = get_line(buf, row)
  if offset_encoding == nil then
    vim.notify_once(
      'character_offset must be called with valid offset encoding',
      vim.log.levels.WARN
    )
    offset_encoding = assert(vim.lsp.get_clients({ bufnr = buf })[1]).offset_encoding
  end
  return vim.str_utfindex(line, offset_encoding, col, false)
end

--- Helper function to return nested values in language server settings
---
---@param settings table language server settings
---@param section  string indicating the field of the settings table
---@return table|string|vim.NIL The value of settings accessed via section. `vim.NIL` if not found.
---@deprecated
function M.lookup_section(settings, section)
  vim.deprecate('vim.lsp.util.lookup_section()', 'vim.tbl_get() with `vim.split`', '0.12')
  for part in vim.gsplit(section, '.', { plain = true }) do
    --- @diagnostic disable-next-line:no-unknown
    settings = settings[part]
    if settings == nil then
      return vim.NIL
    end
  end
  return settings
end

--- Converts line range (0-based, end-inclusive) to lsp range,
--- handles absence of a trailing newline
---
---@param bufnr integer
---@param start_line integer
---@param end_line integer
---@param position_encoding 'utf-8'|'utf-16'|'utf-32'
---@return lsp.Range
function M._make_line_range_params(bufnr, start_line, end_line, position_encoding)
  local last_line = api.nvim_buf_line_count(bufnr) - 1

  ---@type lsp.Position
  local end_pos