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 e8dfebf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
10 changes: 10 additions & 0 deletions lua/lsp_signature/helper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,16 @@ function helper.check_lsp_cap(clients, line_to_cursor)
return signature_cap, triggered, trigger_position, triggered_chars
end

helper.make_position_params = function()
if vim.fn.has "nvim-0.11" == 0 then
return vim.lsp.util.make_position_params()
end
---@param client vim.lsp.Client
return function(client)
return vim.lsp.util.make_position_params(nil, client.offset_encoding)
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
6 changes: 3 additions & 3 deletions lua/lsp_signature/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ local signature = function(opts)
end
end

local params = vim.lsp.util.make_position_params()
local params = helper.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
Expand Down Expand Up @@ -1074,7 +1074,7 @@ M.check_signature_should_close = function()
status_line = { hint = '', label = '' }
return
end
local params = vim.lsp.util.make_position_params()
local params = helper.make_position_params()
params.position.character = math.max(trigger_position, 1)
line = api.nvim_get_current_line()
line_to_cursor = line:sub(1, pos[2])
Expand Down Expand Up @@ -1148,7 +1148,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 e8dfebf

Please sign in to comment.