Skip to content

Commit

Permalink
fix: make_position_params needs offset encoding in v0.11
Browse files Browse the repository at this point in the history
vim.lsp.util.make_position_params requires the explicit client
encoding as of nvim v0.11

Fixes: ray-x#346
  • Loading branch information
brunnre8 committed Dec 23, 2024
1 parent fc38521 commit 15da2ac
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
20 changes: 20 additions & 0 deletions lua/lsp_signature/helper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,26 @@ function helper.check_lsp_cap(clients, line_to_cursor)
return signature_cap, triggered, trigger_position, triggered_chars
end

---@param extra_params table extends the position parameters
---@return table|(fun(client: vim.lsp.Client): table) final parameters
helper.make_position_params = function(extra_params)
if vim.fn.has "nvim-0.11" == 0 then
local params = vim.lsp.util.make_position_params()
if extra_params then
params = vim.tbl_extend("force", params, extra_params)
end
return params
end
---@param client vim.lsp.Client
return function(client)
local params = vim.lsp.util.make_position_params(nil, client.offset_encoding)
if extra_params then
params = vim.tbl_extend("force", params, extra_params)
end
return params
end
end

helper.highlight_parameter = function(s, l)
_LSP_SIG_CFG.ns = api.nvim_create_namespace('lsp_signature_hi_parameter')
local hi = _LSP_SIG_CFG.hi_parameter
Expand Down
17 changes: 11 additions & 6 deletions lua/lsp_signature/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -708,10 +708,12 @@ local signature = function(opts)
end
end

local params = vim.lsp.util.make_position_params()
log('change trigger pos to ', params.position.character, trigger_position)
local shift = math.max(1, trigger_position - 0)
params.position.character = shift
local params = helper.make_position_params({
position = {
character = shift,
},
})
if opts.trigger == 'CursorHold' then
return vim.lsp.buf_request(
0,
Expand Down Expand Up @@ -1074,8 +1076,11 @@ M.check_signature_should_close = function()
status_line = { hint = '', label = '' }
return
end
local params = vim.lsp.util.make_position_params()
params.position.character = math.max(trigger_position, 1)
local params = helper.make_position_params({
position = {
character = math.max(trigger_position, 1),
},
})
line = api.nvim_get_current_line()
line_to_cursor = line:sub(1, pos[2])
-- Try using the already binded one, otherwise use it without custom config.
Expand Down Expand Up @@ -1148,7 +1153,7 @@ M.toggle_float_win = function()
return _LSP_SIG_CFG.floating_window
end

local params = vim.lsp.util.make_position_params()
local params = helper.make_position_params()
local pos = api.nvim_win_get_cursor(0)
local line = api.nvim_get_current_line()
local line_to_cursor = line:sub(1, pos[2])
Expand Down

0 comments on commit 15da2ac

Please sign in to comment.