mirror of
https://github.com/neovim/neovim.git
synced 2025-10-21 17:21:49 +00:00
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:
@@ -85,6 +85,29 @@ function M.on_inlayhint(err, result, ctx)
|
||||
api.nvim__redraw({ buf = bufnr, valid = true, flush = false })
|
||||
end
|
||||
|
||||
--- Refresh inlay hints, only if we have attached clients that support it
|
||||
---@param bufnr (integer) Buffer handle, or 0 for current
|
||||
---@param client_id? (integer) Client ID, or nil for all
|
||||
local function refresh(bufnr, client_id)
|
||||
for _, client in
|
||||
ipairs(vim.lsp.get_clients({
|
||||
bufnr = bufnr,
|
||||
id = client_id,
|
||||
method = ms.textDocument_inlayHint,
|
||||
}))
|
||||
do
|
||||
client:request(ms.textDocument_inlayHint, {
|
||||
textDocument = util.make_text_document_params(bufnr),
|
||||
range = util._make_line_range_params(
|
||||
bufnr,
|
||||
0,
|
||||
api.nvim_buf_line_count(bufnr) - 1,
|
||||
client.offset_encoding
|
||||
),
|
||||
}, nil, bufnr)
|
||||
end
|
||||
end
|
||||
|
||||
--- |lsp-handler| for the method `workspace/inlayHint/refresh`
|
||||
---@param ctx lsp.HandlerContext
|
||||
---@private
|
||||
@@ -97,7 +120,7 @@ function M.on_refresh(err, _, ctx)
|
||||
if api.nvim_win_get_buf(winid) == bufnr then
|
||||
if bufstates[bufnr] and bufstates[bufnr].enabled then
|
||||
bufstates[bufnr].applied = {}
|
||||
util._refresh(ms.textDocument_inlayHint, { bufnr = bufnr })
|
||||
refresh(bufnr)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -229,22 +252,13 @@ local function _disable(bufnr)
|
||||
bufstates[bufnr].enabled = false
|
||||
end
|
||||
|
||||
--- Refresh inlay hints, only if we have attached clients that support it
|
||||
---@param bufnr (integer) Buffer handle, or 0 for current
|
||||
---@param opts? vim.lsp.util._refresh.Opts Additional options to pass to util._refresh
|
||||
local function _refresh(bufnr, opts)
|
||||
opts = opts or {}
|
||||
opts['bufnr'] = bufnr
|
||||
util._refresh(ms.textDocument_inlayHint, opts)
|
||||
end
|
||||
|
||||
--- Enable inlay hints for a buffer
|
||||
---@param bufnr (integer) Buffer handle, or 0 for current
|
||||
local function _enable(bufnr)
|
||||
bufnr = vim._resolve_bufnr(bufnr)
|
||||
bufstates[bufnr] = nil
|
||||
bufstates[bufnr].enabled = true
|
||||
_refresh(bufnr)
|
||||
refresh(bufnr)
|
||||
end
|
||||
|
||||
api.nvim_create_autocmd('LspNotify', {
|
||||
@@ -259,7 +273,7 @@ api.nvim_create_autocmd('LspNotify', {
|
||||
return
|
||||
end
|
||||
if bufstates[bufnr].enabled then
|
||||
_refresh(bufnr, { client_id = args.data.client_id })
|
||||
refresh(bufnr, args.data.client_id)
|
||||
end
|
||||
end,
|
||||
group = augroup,
|
||||
@@ -274,7 +288,7 @@ api.nvim_create_autocmd('LspAttach', {
|
||||
clear(cb_bufnr)
|
||||
if bufstates[cb_bufnr] and bufstates[cb_bufnr].enabled then
|
||||
bufstates[cb_bufnr].applied = {}
|
||||
_refresh(cb_bufnr)
|
||||
refresh(cb_bufnr)
|
||||
end
|
||||
end,
|
||||
on_detach = function(_, cb_bufnr)
|
||||
|
Reference in New Issue
Block a user