aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/lsp.lua
diff options
context:
space:
mode:
authorLewis Russell <lewis6991@gmail.com>2024-10-24 10:18:36 +0100
committerLewis Russell <lewis6991@gmail.com>2024-10-24 10:53:06 +0100
commit2dcbfe78fcec5f73ce061bb24b718187b9c6b134 (patch)
tree7e8f780565d187f0da993b13a470a5f423ff87db /runtime/lua/vim/lsp.lua
parent3275ae830da97ef907ff3cfb0170706b6a430f57 (diff)
downloadrneovim-2dcbfe78fcec5f73ce061bb24b718187b9c6b134.tar.gz
rneovim-2dcbfe78fcec5f73ce061bb24b718187b9c6b134.tar.bz2
rneovim-2dcbfe78fcec5f73ce061bb24b718187b9c6b134.zip
fix(lsp.buf): use correct offset_encoding for all requests
Problem: `lsp.buf_request` send the same params to all servers and many calls to this pass PositionalParams which depends on the clients offset_encoding. This can result with incorrect params being sent to a server. Solution: `lsp.buf_request` `params` argument can now be passed as a function which takes the client as the first argument. This is used in lsp/buf.lua to construct correct params for each client request.
Diffstat (limited to 'runtime/lua/vim/lsp.lua')
-rw-r--r--runtime/lua/vim/lsp.lua5
1 files changed, 3 insertions, 2 deletions
diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua
index 76658b7012..4f13ad5721 100644
--- a/runtime/lua/vim/lsp.lua
+++ b/runtime/lua/vim/lsp.lua
@@ -854,7 +854,7 @@ api.nvim_create_autocmd('VimLeavePre', {
---
---@param bufnr (integer) Buffer handle, or 0 for current.
---@param method (string) LSP method name
----@param params table|nil Parameters to send to the server
+---@param params? table|(fun(client: vim.lsp.Client, bufnr: integer): table?) Parameters to send to the server
---@param handler? lsp.Handler See |lsp-handler|
--- If nil, follows resolution strategy defined in |lsp-handler-configuration|
---@param on_unsupported? fun()
@@ -879,7 +879,8 @@ function lsp.buf_request(bufnr, method, params, handler, on_unsupported)
if client.supports_method(method, { bufnr = bufnr }) then
method_supported = true
- local request_success, request_id = client.request(method, params, handler, bufnr)
+ local cparams = type(params) == 'function' and params(client, bufnr) or params --[[@as table?]]
+ local request_success, request_id = client.request(method, cparams, handler, bufnr)
-- This could only fail if the client shut down in the time since we looked
-- it up and we did the request, which should be rare.
if request_success then