--- @brief
--- The `vim.lsp.buf_…` functions perform operations for LSP clients attached to the current buffer.
local api = vim.api
local nvim_on = require('vim._core.util').nvim_on
local lsp = vim.lsp
local validate = vim.validate
local util = require('vim.lsp.util')
local npcall = vim.npcall
local Range = require('vim.treesitter._range')
local M = {}
--- @param params? table
--- @return fun(client: vim.lsp.Client): lsp.TextDocumentPositionParams
local function client_positional_params(params)
local win = api.nvim_get_current_win()
return function(client)
local ret = util.make_position_params(win, client.offset_encoding)
if params then
ret = vim.tbl_extend('force', ret, params)
end
return ret
end
end
local hover_ns = api.nvim_create_namespace('nvim.lsp.hover_range')
local rename_ns = api.nvim_create_namespace('nvim.lsp.rename_range')
--- Returns false if the LSP response is stale and should be discarded.
--- @param ctx lsp.HandlerContext
--- @return boolean
local function ctx_is_valid(ctx)
local bufnr = ctx.bufnr
if
not bufnr
or not api.nvim_buf_is_valid(bufnr)
or api.nvim_get_current_buf() ~= bufnr
or lsp.util.buf_versions[bufnr] ~= ctx.version
then
return false
end
---@type lsp.Position?
local p = ctx.params and ctx.params.position
if not p then
return true
end
local c = lsp.get_client_by_id(ctx.client_id)
local enc = c and c.offset_encoding
if not enc then
return false
end
local cur_pos = vim.pos.cursor(0)
local pos = vim.pos.lsp(bufnr, p, enc)
return cur_pos == pos
end
--- @class vim.lsp.buf.hover.Opts : vim.lsp.util.open_floating_preview.Opts
--- @field silent? boolean
--- Displays hover information about th
|