From bb14e22795e026189f0b69fb705a3c73e3bb311b Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 12 Jul 2022 09:44:30 +0200 Subject: [PATCH] [Backport release-0.7] fix(lsp): abort pending changes after flush when debouncing (#19318) fix(lsp): abort pending changes after flush when debouncing Issuing a server request triggers `changetracking.flush` so as to make sure we're not operating on a stale state. This immediately triggers notification of any pending changes (as a result of debouncing) to the server. However, this happens in addition to the notification that is waiting on the debounce delay. Because we `nil` `buf_state.pending_change` when it is called, the fix is to also check that this is non-`nil` when it is called and exit if it is, as this being `nil` would mean that it originates from a pending change that has already been flushed out. (cherry picked from commit d7bb2b42022bebb4cadd4df86b494f28a3c6c467) Co-authored-by: Rishikesh Vaishnav --- runtime/lua/vim/lsp.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua index 7bbe3637db..039417eab6 100644 --- a/runtime/lua/vim/lsp.lua +++ b/runtime/lua/vim/lsp.lua @@ -460,6 +460,9 @@ do table.insert(buf_state.pending_changes, incremental_changes(client, buf_state)) end buf_state.pending_change = function() + if buf_state.pending_change == nil then + return + end buf_state.pending_change = nil buf_state.last_flush = uv.hrtime() if client.is_stopped() or not vim.api.nvim_buf_is_valid(bufnr) then