From 2a5164f0782bc1d3a78e86af8d9d46f9cce1c5e6 Mon Sep 17 00:00:00 2001 From: jinzhongjia Date: Wed, 1 Jan 2025 11:26:46 +0800 Subject: [PATCH 1/3] fix: signatureHelp error on basedpyright --- lua/LspUI/signature/util.lua | 37 ++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/lua/LspUI/signature/util.lua b/lua/LspUI/signature/util.lua index 3392cfc..d812b1f 100644 --- a/lua/LspUI/signature/util.lua +++ b/lua/LspUI/signature/util.lua @@ -18,8 +18,9 @@ local is_there_virtual_text = false --- @field doc string? --- @param help lsp.SignatureHelp|nil +--- @param client_name string|nil --- @return signature_info? res len will not be zero -local build_signature_info = function(help) +local build_signature_info = function(help, client_name) if not help then return nil end @@ -27,11 +28,17 @@ local build_signature_info = function(help) return nil end - local active_signature = help.activeSignature and help.activeSignature + 1 - or 1 - local active_parameter = help.activeParameter and help.activeParameter + 1 - or 1 - + local active_signature, active_parameter + -- this logic is in order to handle certain lsp specification implementations that are not standard + if client_name == "basedpyright" then + active_signature = help.activeSignature and help.activeSignature or 1 + active_parameter = help.activeParameter and help.activeParameter or 1 + else + active_signature = help.activeSignature and help.activeSignature + 1 + or 1 + active_parameter = help.activeParameter and help.activeParameter + 1 + or 1 + end --- @type signature_info ---@diagnostic disable-next-line: missing-fields local res = {} @@ -90,11 +97,11 @@ local signature_group local signature_namespace = api.nvim_create_namespace("LspUI_signature") ---- @type { data: lsp.SignatureHelp?, } +--- @type { data: lsp.SignatureHelp?,client_name:string|nil } local backup = {} --- @param buffer_id number buffer's id ---- @param callback fun(result: lsp.SignatureHelp|nil) callback function +--- @param callback fun(result: lsp.SignatureHelp|nil,client_name:string|nil) callback function M.request = function(buffer_id, callback) -- this buffer id maybe invalid if not api.nvim_buf_is_valid(buffer_id) then @@ -127,7 +134,7 @@ M.request = function(buffer_id, callback) ) return end - callback(result) + callback(result, client.name) end, buffer_id ) @@ -156,8 +163,9 @@ local signature_handle = function() backup.data = nil return end - M.request(current_buffer, function(result) + M.request(current_buffer, function(result, client_name) backup.data = result + backup.client_name = client_name local mode_info = vim.api.nvim_get_mode() local mode = mode_info["mode"] @@ -175,7 +183,7 @@ local signature_handle = function() end local current_window = api.nvim_get_current_win() - M.render(result, current_buffer, current_window) + M.render(result, current_buffer, current_window, client_name) end) end @@ -197,8 +205,9 @@ end --- @param data lsp.SignatureHelp|nil --- @param buffer_id integer --- @param windows_id integer -M.render = function(data, buffer_id, windows_id) - local info = build_signature_info(data) +--- @param client_name string|nil +M.render = function(data, buffer_id, windows_id, client_name) + local info = build_signature_info(data, client_name) if not info then return end @@ -304,7 +313,7 @@ end --- @return signature_info? M.status_line = function() - return build_signature_info(backup.data) + return build_signature_info(backup.data, backup.client_name) end return M From 0d48f54f6e6a6f50f0f98f7d7beccbbaa7ac6c78 Mon Sep 17 00:00:00 2001 From: jinzhongjia Date: Wed, 8 Jan 2025 13:03:55 +0800 Subject: [PATCH 2/3] little fix --- lua/LspUI/lib/util.lua | 16 ++++++++++++++++ lua/LspUI/signature/util.lua | 9 ++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lua/LspUI/lib/util.lua b/lua/LspUI/lib/util.lua index 46a426e..d25d7ec 100644 --- a/lua/LspUI/lib/util.lua +++ b/lua/LspUI/lib/util.lua @@ -241,4 +241,20 @@ function M.trim_empty_lines(lines) return vim.list_extend({}, lines, start, finish) end +-- 定义一个函数,将消息写入文件 +--- @param message any +---@param file_path string +function M.write_message_to_file(message, file_path) + local fd = uv.fs_open(file_path, "a", 438) -- 438 是文件权限,等同于 0666 + if not fd then + print("无法打开文件: " .. file_path) + return + end + + local stat = uv.fs_fstat(fd) + ---@diagnostic disable-next-line: need-check-nil + uv.fs_write(fd, message .. "\n", stat.size) + uv.fs_close(fd) +end + return M diff --git a/lua/LspUI/signature/util.lua b/lua/LspUI/signature/util.lua index d812b1f..7134d3b 100644 --- a/lua/LspUI/signature/util.lua +++ b/lua/LspUI/signature/util.lua @@ -28,10 +28,17 @@ local build_signature_info = function(help, client_name) return nil end + -- TODO: this is some debug info, maybe remove + -- write_message_to_file( + -- vim.inspect(help), + -- "C:\\Users\\jin\\Downloads\\log.txt" + -- ) + local active_signature, active_parameter -- this logic is in order to handle certain lsp specification implementations that are not standard if client_name == "basedpyright" then - active_signature = help.activeSignature and help.activeSignature or 1 + active_signature = help.activeSignature and help.activeSignature + 1 + or 1 active_parameter = help.activeParameter and help.activeParameter or 1 else active_signature = help.activeSignature and help.activeSignature + 1 From 4e267f766ab0d7a4644e0a3c9b6e41e030b0215d Mon Sep 17 00:00:00 2001 From: jinzhongjia Date: Wed, 8 Jan 2025 21:58:06 +0800 Subject: [PATCH 3/3] little fix --- lua/LspUI/signature/util.lua | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/lua/LspUI/signature/util.lua b/lua/LspUI/signature/util.lua index 7134d3b..78efada 100644 --- a/lua/LspUI/signature/util.lua +++ b/lua/LspUI/signature/util.lua @@ -29,23 +29,21 @@ local build_signature_info = function(help, client_name) end -- TODO: this is some debug info, maybe remove - -- write_message_to_file( + -- lib_util.write_message_to_file( -- vim.inspect(help), -- "C:\\Users\\jin\\Downloads\\log.txt" -- ) local active_signature, active_parameter -- this logic is in order to handle certain lsp specification implementations that are not standard - if client_name == "basedpyright" then - active_signature = help.activeSignature and help.activeSignature + 1 - or 1 - active_parameter = help.activeParameter and help.activeParameter or 1 - else - active_signature = help.activeSignature and help.activeSignature + 1 - or 1 - active_parameter = help.activeParameter and help.activeParameter + 1 - or 1 - end + -- if client_name == "basedpyright" then + -- active_signature = help.activeSignature and help.activeSignature + 1 + -- or 1 + -- active_parameter = help.activeParameter and help.activeParameter or 1 + -- else + active_signature = help.activeSignature and help.activeSignature + 1 or 1 + active_parameter = help.activeParameter and help.activeParameter + 1 or 1 + -- end --- @type signature_info ---@diagnostic disable-next-line: missing-fields local res = {} @@ -53,6 +51,8 @@ local build_signature_info = function(help, client_name) local signature = help.signatures[active_signature] if signature.activeParameter then active_parameter = signature.activeParameter + 1 + elseif active_parameter > #signature - 1 then + active_parameter = 1 end res.label = signature.label @@ -121,6 +121,12 @@ M.request = function(buffer_id, callback) end local params = lsp.util.make_position_params() + -- TODO: this is debug info should be removed + -- lib_util.write_message_to_file( + -- vim.inspect(params), + -- "C:\\Users\\jin\\Downloads\\log1.txt" + -- ) + -- NOTE: we just use one client to get the lsp signature local client = clients[1] -- for _, client in pairs(clients or {}) do