Skip to content

Commit df4b5e4

Browse files
authored
fix document state getting out of sync in rare cases (#2375)
1 parent 97b5558 commit df4b5e4

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

plugin/session_buffer.py

+5
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ def __init__(self, session_view: SessionViewProtocol, buffer_id: int, uri: Docum
120120
self._diagnostics_are_visible = False
121121
self.document_diagnostic_needs_refresh = False
122122
self._document_diagnostic_pending_response = None # type: Optional[int]
123+
self._last_synced_version = 0
123124
self._last_text_change_time = 0.0
124125
self._diagnostics_debouncer_async = DebouncerNonThreadSafe(async_thread=True)
125126
self._workspace_diagnostics_debouncer_async = DebouncerNonThreadSafe(async_thread=True)
@@ -156,6 +157,7 @@ def _check_did_open(self, view: sublime.View) -> None:
156157
self.session.send_notification(did_open(view, language_id))
157158
self.opened = True
158159
version = view.change_count()
160+
self._last_synced_version = version
159161
self._do_color_boxes_async(view, version)
160162
self.do_document_diagnostic_async(view, version)
161163
self.do_semantic_tokens_async(view, view.size() > HUGE_FILE_SIZE)
@@ -277,6 +279,8 @@ def should_notify_did_close(self) -> bool:
277279

278280
def on_text_changed_async(self, view: sublime.View, change_count: int,
279281
changes: Iterable[sublime.TextChange]) -> None:
282+
if change_count <= self._last_synced_version:
283+
return
280284
self._last_text_change_time = time.time()
281285
last_change = list(changes)[-1]
282286
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:
319323
try:
320324
notification = did_change(view, version, changes)
321325
self.session.send_notification(notification)
326+
self._last_synced_version = version
322327
except MissingUriError:
323328
return # we're closing
324329
finally:

0 commit comments

Comments
 (0)