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 stale state or lack of updates on changing branches #2182

Merged
merged 4 commits into from
Jan 29, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
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
Comment on lines +907 to +909
Copy link
Member Author

@rchl rchl Jan 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As has been mentioned in some other issue, it's not really correct to return here if region didn't change as the file might still have changed (especially on file "reload"). The impact of this is very small currently though - pretty much only symbol highlights could misbehave.

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