From df4b5e44916f3afc860204f257c3ca40a92abb96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Ch=C5=82odnicki?= Date: Wed, 13 Dec 2023 14:52:23 +0100 Subject: [PATCH] fix document state getting out of sync in rare cases (#2375) --- plugin/session_buffer.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugin/session_buffer.py b/plugin/session_buffer.py index be61df511..71febb56b 100644 --- a/plugin/session_buffer.py +++ b/plugin/session_buffer.py @@ -120,6 +120,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) @@ -156,6 +157,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) @@ -277,6 +279,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 change_count <= self._last_synced_version: + 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: @@ -319,6 +323,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: