From d6c298824c93b3ccb184106653cceed41d8ef91f Mon Sep 17 00:00:00 2001 From: Rafal Chlodnicki Date: Sat, 2 Nov 2024 16:56:54 +0100 Subject: [PATCH] fix: cancel pending requests as early as possible --- plugin/session_buffer.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/plugin/session_buffer.py b/plugin/session_buffer.py index 28b7e6b96..10b53fbad 100644 --- a/plugin/session_buffer.py +++ b/plugin/session_buffer.py @@ -311,9 +311,18 @@ def on_text_changed_async(self, view: sublime.View, change_count: int, self._pending_changes.update(change_count, changes) purge = True if purge: + self._cancel_pending_requests_async() debounced(lambda: self.purge_changes_async(view), FEATURES_TIMEOUT, lambda: view.is_valid() and change_count == view.change_count(), async_thread=True) + def _cancel_pending_requests_async(self) -> None: + if self._document_diagnostic_pending_request: + self.session.cancel_request(self._document_diagnostic_pending_request.request_id) + self._document_diagnostic_pending_request = None + if self.semantic_tokens.pending_response: + self.session.cancel_request(self.semantic_tokens.pending_response) + self.semantic_tokens.pending_response = None + def on_revert_async(self, view: sublime.View) -> None: self._pending_changes = None # Don't bother with pending changes version = view.change_count()