fix(lsp): update lsp-handler signature in call_hierarchy (#15738)

This fixes the handler signature and also prevents n+1 requests firing
if there are multiple clients.

(The first `prepareCallHierarchy` handler is called once per client,
each invocation used `buf_request` to make more requests using *all*
clients)
This commit is contained in:
Mathias Fußenegger 2021-09-22 00:05:49 +02:00 committed by GitHub
parent a65d8c34e6
commit 8164adc144
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -321,13 +321,21 @@ end
---@private
local function call_hierarchy(method)
local params = util.make_position_params()
request('textDocument/prepareCallHierarchy', params, function(err, _, result)
request('textDocument/prepareCallHierarchy', params, function(err, result, ctx)
if err then
vim.notify(err.message, vim.log.levels.WARN)
return
end
local call_hierarchy_item = pick_call_hierarchy_item(result)
vim.lsp.buf_request(0, method, { item = call_hierarchy_item })
local client = vim.lsp.get_client_by_id(ctx.client_id)
if client then
client.request(method, { item = call_hierarchy_item }, nil, ctx.bufnr)
else
vim.notify(string.format(
'Client with id=%d disappeared during call hierarchy request', ctx.client_id),
vim.log.levels.WARN
)
end
end)
end