From 4fd2694f20d6abe4305e3f37ca06cf86762ad6a2 Mon Sep 17 00:00:00 2001 From: Yi Ming Date: Thu, 13 Feb 2025 10:19:34 +0800 Subject: fix(lsp): missing method parameter when canceling requests --- runtime/lua/vim/lsp/util.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'runtime/lua') diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua index ba519614c0..9e84e27205 100644 --- a/runtime/lua/vim/lsp/util.lua +++ b/runtime/lua/vim/lsp/util.lua @@ -2218,6 +2218,7 @@ function M._refresh(method, opts) M._cancel_requests({ bufnr = bufnr, clients = clients, + method = method, type = 'pending', }) for _, client in ipairs(clients) do -- cgit From d76f7fef13e534cce870cbce6b1bfaecd18bd034 Mon Sep 17 00:00:00 2001 From: Yi Ming Date: Thu, 13 Feb 2025 11:51:31 +0800 Subject: fix(lsp): reset active request when reporting an error --- runtime/lua/vim/lsp/semantic_tokens.lua | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'runtime/lua') diff --git a/runtime/lua/vim/lsp/semantic_tokens.lua b/runtime/lua/vim/lsp/semantic_tokens.lua index 619f7f1110..9aa93862bc 100644 --- a/runtime/lua/vim/lsp/semantic_tokens.lua +++ b/runtime/lua/vim/lsp/semantic_tokens.lua @@ -294,9 +294,16 @@ function STHighlighter:send_request() local c = vim.lsp.get_client_by_id(ctx.client_id) local bufnr = assert(ctx.bufnr) local highlighter = STHighlighter.active[bufnr] - if not err and c and highlighter then - coroutine.wrap(STHighlighter.process_response)(highlighter, response, c, version) + if not (c and highlighter) then + return end + + if err then + highlighter.client_state[c.id].active_request = {} + return + end + + coroutine.wrap(STHighlighter.process_response)(highlighter, response, c, version) end, self.bufnr) if success then -- cgit From 2df68d3696c0e48a9b6c23b654754942504dce34 Mon Sep 17 00:00:00 2001 From: Yi Ming Date: Thu, 13 Feb 2025 12:01:16 +0800 Subject: refactor(lsp): handling errors and nil responses together --- runtime/lua/vim/lsp/semantic_tokens.lua | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'runtime/lua') diff --git a/runtime/lua/vim/lsp/semantic_tokens.lua b/runtime/lua/vim/lsp/semantic_tokens.lua index 9aa93862bc..5f60b732de 100644 --- a/runtime/lua/vim/lsp/semantic_tokens.lua +++ b/runtime/lua/vim/lsp/semantic_tokens.lua @@ -288,6 +288,7 @@ function STHighlighter:send_request() method = method .. '/delta' params.previousResultId = current_result.result_id end + ---@param response? lsp.SemanticTokens|lsp.SemanticTokensDelta local success, request_id = client:request(method, params, function(err, response, ctx) -- look client up again using ctx.client_id instead of using a captured -- client object @@ -298,7 +299,7 @@ function STHighlighter:send_request() return end - if err then + if err or not response then highlighter.client_state[c.id].active_request = {} return end @@ -338,12 +339,6 @@ function STHighlighter:process_response(response, client, version) return end - -- skip nil responses - if response == nil then - state.active_request = {} - return - end - if not api.nvim_buf_is_valid(self.bufnr) then return end -- cgit