Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix document state getting out of sync in rare cases #2375

Merged
merged 3 commits into from
Dec 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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