Skip to content

Commit

Permalink
fix stale state or lack of updates on changing branches (#2182)
Browse files Browse the repository at this point in the history
  • Loading branch information
rchl authored Jan 29, 2023
1 parent 9605522 commit a2d137e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
25 changes: 15 additions & 10 deletions plugin/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,19 +320,10 @@ def session_buffers_async(self) -> Generator[SessionBuffer, None, None]:
yield sv.session_buffer

def on_text_changed_async(self, change_count: int, changes: Iterable[sublime.TextChange]) -> None:
different, current_region = self._update_stored_region_async()
if self.view.is_primary():
for sv in self.session_views_async():
sv.on_text_changed_async(change_count, changes)
self._code_lenses_debouncer_async.debounce(
self._do_code_lenses_async, timeout_ms=self.code_lenses_debounce_time)
if not different:
return
self._clear_highlight_regions()
if userprefs().document_highlight_style:
self._when_selection_remains_stable_async(self._do_highlights_async, current_region,
after_ms=self.highlights_debounce_time)
self.do_signature_help_async(manual=False)
self._on_view_updated_async()

def get_uri(self) -> DocumentUri:
return self._uri
Expand Down Expand Up @@ -867,11 +858,13 @@ def revert_async(self) -> None:
if self.view.is_primary():
for sv in self.session_views_async():
sv.on_revert_async()
self._on_view_updated_async()

def reload_async(self) -> None:
if self.view.is_primary():
for sv in self.session_views_async():
sv.on_reload_async()
self._on_view_updated_async()

# --- Private utility methods --------------------------------------------------------------------------------------

Expand Down Expand Up @@ -908,6 +901,18 @@ def _register_async(self) -> None:
debug("also registering", listener)
listener.on_load_async()

def _on_view_updated_async(self) -> None:
self._code_lenses_debouncer_async.debounce(
self._do_code_lenses_async, timeout_ms=self.code_lenses_debounce_time)
different, current_region = self._update_stored_region_async()
if not different:
return
self._clear_highlight_regions()
if userprefs().document_highlight_style:
self._when_selection_remains_stable_async(
self._do_highlights_async, current_region, after_ms=self.highlights_debounce_time)
self.do_signature_help_async(manual=False)

def _update_stored_region_async(self) -> Tuple[bool, sublime.Region]:
"""
Stores the current first selection in a variable.
Expand Down
4 changes: 3 additions & 1 deletion plugin/session_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,9 @@ def on_text_changed_async(self, view: sublime.View, change_count: int,

def on_revert_async(self, view: sublime.View) -> None:
self.pending_changes = None # Don't bother with pending changes
self.session.send_notification(did_change(view, view.change_count(), None))
version = view.change_count()
self.session.send_notification(did_change(view, version, None))
sublime.set_timeout_async(lambda: self._on_after_change_async(view, version))

on_reload_async = on_revert_async

Expand Down

0 comments on commit a2d137e

Please sign in to comment.