mirror of
https://github.com/neovim/neovim
synced 2025-07-20 13:22:26 +00:00
feat(lsp): include original request params in handler ctx
This is mostly motivated by https://github.com/neovim/neovim/issues/12326 Client side commands might need to access the original request parameters. Currently this is already possible by using closures with `vim.lsp.buf_request`, but the global handlers so far couldn't access the request parameters.
This commit is contained in:
@ -224,6 +224,11 @@ For |lsp-request|, each |lsp-handler| has this signature: >
|
|||||||
The ID of the |vim.lsp.client|.
|
The ID of the |vim.lsp.client|.
|
||||||
{bufnr} (Buffer)
|
{bufnr} (Buffer)
|
||||||
Buffer handle, or 0 for current.
|
Buffer handle, or 0 for current.
|
||||||
|
|
||||||
|
{params} (table|nil)
|
||||||
|
The parameters used in the original request
|
||||||
|
which resulted in this handler
|
||||||
|
call.
|
||||||
{config} (table)
|
{config} (table)
|
||||||
Configuration for the handler.
|
Configuration for the handler.
|
||||||
|
|
||||||
@ -234,6 +239,7 @@ For |lsp-request|, each |lsp-handler| has this signature: >
|
|||||||
To configure a particular |lsp-handler|, see:
|
To configure a particular |lsp-handler|, see:
|
||||||
|lsp-handler-configuration|
|
|lsp-handler-configuration|
|
||||||
|
|
||||||
|
|
||||||
Returns: ~
|
Returns: ~
|
||||||
The |lsp-handler| can respond by returning two values: `result, err`
|
The |lsp-handler| can respond by returning two values: `result, err`
|
||||||
Where `err` must be shaped like an RPC error:
|
Where `err` must be shaped like an RPC error:
|
||||||
|
@ -896,7 +896,7 @@ function lsp.start_client(config)
|
|||||||
|
|
||||||
local _ = log.debug() and log.debug(log_prefix, "client.request", client_id, method, params, handler, bufnr)
|
local _ = log.debug() and log.debug(log_prefix, "client.request", client_id, method, params, handler, bufnr)
|
||||||
return rpc.request(method, params, function(err, result)
|
return rpc.request(method, params, function(err, result)
|
||||||
handler(err, result, {method=method, client_id=client_id, bufnr=bufnr})
|
handler(err, result, {method=method, client_id=client_id, bufnr=bufnr, params=params})
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -2353,6 +2353,10 @@ describe('LSP', function()
|
|||||||
eq(0, signal, "exit signal", fake_lsp_logfile)
|
eq(0, signal, "exit signal", fake_lsp_logfile)
|
||||||
end;
|
end;
|
||||||
on_handler = function(err, result, ctx)
|
on_handler = function(err, result, ctx)
|
||||||
|
-- Don't compare & assert params, they're not relevant for the testcase
|
||||||
|
-- This allows us to be lazy and avoid declaring them
|
||||||
|
ctx.params = nil
|
||||||
|
|
||||||
eq(table.remove(test.expected_handlers), {err, result, ctx}, "expected handler")
|
eq(table.remove(test.expected_handlers), {err, result, ctx}, "expected handler")
|
||||||
if ctx.method == 'start' then
|
if ctx.method == 'start' then
|
||||||
exec_lua("vim.lsp.buf.rename()")
|
exec_lua("vim.lsp.buf.rename()")
|
||||||
|
Reference in New Issue
Block a user