From 306108db947b063845e5c1dd9bef89bb8b773a48 Mon Sep 17 00:00:00 2001 From: Rafal Chlodnicki Date: Wed, 13 Dec 2023 01:09:04 +0100 Subject: [PATCH 1/2] fix document state getting out of sync in rare cases --- plugin/session_buffer.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugin/session_buffer.py b/plugin/session_buffer.py index 2012b97c7..497c90ff2 100644 --- a/plugin/session_buffer.py +++ b/plugin/session_buffer.py @@ -119,6 +119,7 @@ def __init__(self, session_view: SessionViewProtocol, buffer_id: int, uri: Docum self._diagnostics_are_visible = False self.document_diagnostic_needs_refresh = False self._document_diagnostic_pending_response = None # type: Optional[int] + self._last_synced_version = 0 self._last_text_change_time = 0.0 self._diagnostics_debouncer_async = DebouncerNonThreadSafe(async_thread=True) self._workspace_diagnostics_debouncer_async = DebouncerNonThreadSafe(async_thread=True) @@ -155,6 +156,7 @@ def _check_did_open(self, view: sublime.View) -> None: self.session.send_notification(did_open(view, language_id)) self.opened = True version = view.change_count() + self._last_synced_version = version self._do_color_boxes_async(view, version) self.do_document_diagnostic_async(view, version) self.do_semantic_tokens_async(view, view.size() > HUGE_FILE_SIZE) @@ -276,6 +278,8 @@ def should_notify_did_close(self) -> bool: def on_text_changed_async(self, view: sublime.View, change_count: int, changes: Iterable[sublime.TextChange]) -> None: + if self._last_synced_version >= change_count: + return self._last_text_change_time = time.time() last_change = list(changes)[-1] if last_change.a.pt == 0 and last_change.b.pt == 0 and last_change.str == '' and view.size() != 0: @@ -318,6 +322,7 @@ def purge_changes_async(self, view: sublime.View) -> None: try: notification = did_change(view, version, changes) self.session.send_notification(notification) + self._last_synced_version = version except MissingUriError: return # we're closing finally: From c359c67976f21e5779c10d6b0f416675f1493135 Mon Sep 17 00:00:00 2001 From: Rafal Chlodnicki Date: Wed, 13 Dec 2023 01:25:50 +0100 Subject: [PATCH 2/2] more readable condition --- plugin/session_buffer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/session_buffer.py b/plugin/session_buffer.py index 497c90ff2..08a6fc683 100644 --- a/plugin/session_buffer.py +++ b/plugin/session_buffer.py @@ -278,7 +278,7 @@ def should_notify_did_close(self) -> bool: def on_text_changed_async(self, view: sublime.View, change_count: int, changes: Iterable[sublime.TextChange]) -> None: - if self._last_synced_version >= change_count: + if change_count <= self._last_synced_version: return self._last_text_change_time = time.time() last_change = list(changes)[-1]