Skip to content

Commit

Permalink
fix document state getting out of sync in rare cases (#2375)
Browse files Browse the repository at this point in the history
  • Loading branch information
rchl authored Dec 13, 2023
1 parent 97b5558 commit df4b5e4
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions plugin/session_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit df4b5e4

Please sign in to comment.