refactor(lsp): drop vim.lsp.util._refresh() #33903

Problem:
- util._refresh() is only used by `inlay_hint.lua` and `document_color.lua`, and
  both have their own wrapper functions;
- util._refresh() provides unified parameters, but this layer of wrapping is
  almost meaningless because
  - document color does not need the range parameter;
  - inlay hint requires a range parameter, but it is not complicated

Therefore, it can be considered redundant.
ref https://github.com/neovim/neovim/pull/32887#discussion_r1996413602

Solution:
Remove it.
This commit is contained in:
Yi Ming
2025-07-13 13:00:10 +08:00
committed by GitHub
parent 89b946aa87
commit 73fbc693b5
3 changed files with 39 additions and 75 deletions

View File

@@ -2224,7 +2224,7 @@ end
---@param end_line integer
---@param position_encoding 'utf-8'|'utf-16'|'utf-32'
---@return lsp.Range
local function make_line_range_params(bufnr, start_line, end_line, position_encoding)
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
@@ -2284,62 +2284,6 @@ function M._cancel_requests(filter)
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
--- Request updated LSP information for a buffer.
---
---@param method vim.lsp.protocol.Method.ClientToServer.Request 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,
type = 'pending',
})
for _, client in ipairs(clients) do
client:request(method, {
textDocument = textDocument,
range = make_line_range_params(bufnr, first - 1, last - 1, client.offset_encoding),
}, opts.handler, bufnr)
end
end
end
else
for _, client in ipairs(clients) do
client:request(method, {
textDocument = textDocument,
range = make_line_range_params(
bufnr,
0,
api.nvim_buf_line_count(bufnr) - 1,
client.offset_encoding
),
}, opts.handler, bufnr)
end
end
end
---@param feature string
---@param client_id? integer
local function make_enable_var(feature, client_id)