From e8dfebf6367c5abffe88beae017e769e5a211db1 Mon Sep 17 00:00:00 2001 From: Reto Brunner Date: Mon, 23 Dec 2024 12:26:01 +0100 Subject: [PATCH] fix: make_position_params needs offset encoding in v0.11 vim.lsp.util.make_position_params requires the explicit client encoding as of nvim v0.11 Fixes: https://github.com/ray-x/lsp_signature.nvim/issues/346 --- lua/lsp_signature/helper.lua | 10 ++++++++++ lua/lsp_signature/init.lua | 6 +++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lua/lsp_signature/helper.lua b/lua/lsp_signature/helper.lua index 4615e1b..1b6644a 100644 --- a/lua/lsp_signature/helper.lua +++ b/lua/lsp_signature/helper.lua @@ -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 diff --git a/lua/lsp_signature/init.lua b/lua/lsp_signature/init.lua index 7a05331..22f9b67 100644 --- a/lua/lsp_signature/init.lua +++ b/lua/lsp_signature/init.lua @@ -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 @@ -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]) @@ -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])