Skip to content

Commit

Permalink
Delegate userprefs changes to Session -> SessionBuffer -> SessionView
Browse files Browse the repository at this point in the history
  • Loading branch information
jwortmann committed Sep 23, 2024
1 parent b2bab2f commit 32d3bef
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 23 deletions.
24 changes: 13 additions & 11 deletions plugin/core/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,9 +580,6 @@ def shutdown_async(self) -> None:
def present_diagnostics_async(self, is_view_visible: bool) -> None:
...

def redraw_diagnostics_async(self) -> None:
...

def on_request_started_async(self, request_id: int, request: Request) -> None:
...

Expand All @@ -607,6 +604,9 @@ def set_code_lenses_pending_refresh(self, needs_refresh: bool = True) -> None:
def reset_show_definitions(self) -> None:
...

def on_userprefs_changed_async(self) -> None:
...


class SessionBufferProtocol(Protocol):

Expand Down Expand Up @@ -654,6 +654,9 @@ def get_capability(self, capability_path: str) -> Any | None:
def has_capability(self, capability_path: str) -> bool:
...

def on_userprefs_changed_async(self) -> None:
...

def on_diagnostics_async(
self, raw_diagnostics: list[Diagnostic], version: int | None, visible_session_views: set[SessionViewProtocol]
) -> None:
Expand All @@ -665,9 +668,6 @@ def get_document_link_at_point(self, view: sublime.View, point: int) -> Document
def update_document_link(self, new_link: DocumentLink) -> None:
...

def redraw_document_links_async(self) -> None:
...

def do_semantic_tokens_async(self, view: sublime.View) -> None:
...

Expand All @@ -677,9 +677,6 @@ def set_semantic_tokens_pending_refresh(self, needs_refresh: bool = True) -> Non
def get_semantic_tokens(self) -> list[Any]:
...

def clear_semantic_tokens_async(self) -> None:
...

def do_inlay_hints_async(self, view: sublime.View) -> None:
...

Expand Down Expand Up @@ -1351,9 +1348,9 @@ def set_config_status_async(self, message: str) -> None:
:param message: The message
"""
self.config_status_message = message.strip()
self.redraw_config_status_async()
self._redraw_config_status_async()

def redraw_config_status_async(self) -> None:
def _redraw_config_status_async(self) -> None:
for sv in self.session_views_async():
self.config.set_view_status(sv.view, self.config_status_message)

Expand Down Expand Up @@ -1490,6 +1487,11 @@ def on_file_event_async(self, events: list[FileWatcherEvent]) -> None:

# --- misc methods -------------------------------------------------------------------------------------------------

def on_userprefs_changed_async(self) -> None:
self._redraw_config_status_async()
for sb in self.session_buffers_async():
sb.on_userprefs_changed_async()

def markdown_language_id_to_st_syntax_map(self) -> MarkdownLangMap | None:
return self._plugin.markdown_language_id_to_st_syntax_map() if self._plugin is not None else None

Expand Down
8 changes: 1 addition & 7 deletions plugin/core/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,13 +535,7 @@ def _on_userprefs_updated_async(self) -> None:
for wm in self._windows.values():
wm.on_diagnostics_updated()
for session in wm.get_sessions():
session.redraw_config_status_async()
for sb in session.session_buffers_async():
sb.redraw_document_links_async()
if not userprefs().semantic_highlighting:
sb.clear_semantic_tokens_async()
for sv in session.session_views_async():
sv.redraw_diagnostics_async()
session.on_userprefs_changed_async()

def enable(self) -> None:
self._enabled = True
Expand Down
13 changes: 10 additions & 3 deletions plugin/session_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,13 @@ def on_post_save_async(self, view: sublime.View, new_uri: DocumentUri) -> None:
self._has_changed_during_save = False
self._on_after_change_async(view, view.change_count())

def on_userprefs_changed_async(self) -> None:
self._redraw_document_links_async()
if not userprefs().semantic_highlighting:
self._clear_semantic_tokens_async()
for sv in self.session_views:
sv.on_userprefs_changed_async()

def some_view(self) -> sublime.View | None:
if not self.session_views:
return None
Expand Down Expand Up @@ -429,9 +436,9 @@ def _do_document_link_async(self, view: sublime.View, version: int) -> None:

def _on_document_link_async(self, view: sublime.View, response: list[DocumentLink] | None) -> None:
self._document_links = response or []
self.redraw_document_links_async()
self._redraw_document_links_async()

def redraw_document_links_async(self) -> None:
def _redraw_document_links_async(self) -> None:
if self._document_links and userprefs().link_highlight_style == "underline":
view = self.some_view()
if not view:
Expand Down Expand Up @@ -715,7 +722,7 @@ def set_semantic_tokens_pending_refresh(self, needs_refresh: bool = True) -> Non
def get_semantic_tokens(self) -> list[SemanticToken]:
return self.semantic_tokens.tokens

def clear_semantic_tokens_async(self) -> None:
def _clear_semantic_tokens_async(self) -> None:
for sv in self.session_views:
self._clear_semantic_token_regions(sv.view)

Expand Down
7 changes: 5 additions & 2 deletions plugin/session_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,12 +300,12 @@ def diagnostics_tag_scope(self, tag: int) -> str | None:
return None

def present_diagnostics_async(self, is_view_visible: bool) -> None:
self.redraw_diagnostics_async()
self._redraw_diagnostics_async()
listener = self.listener()
if listener:
listener.on_diagnostics_updated_async(is_view_visible)

def redraw_diagnostics_async(self) -> None:
def _redraw_diagnostics_async(self) -> None:
flags = userprefs().diagnostics_highlight_style_flags() # for single lines
multiline_flags = None if userprefs().show_multiline_diagnostics_highlights else sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE | sublime.NO_UNDO # noqa: E501
level = userprefs().show_diagnostics_severity_level
Expand Down Expand Up @@ -376,6 +376,9 @@ def on_pre_save_async(self) -> None:
def on_post_save_async(self, new_uri: DocumentUri) -> None:
self.session_buffer.on_post_save_async(self.view, new_uri)

def on_userprefs_changed_async(self) -> None:
self._redraw_diagnostics_async()

# --- textDocument/codeLens ----------------------------------------------------------------------------------------

def start_code_lenses_async(self) -> None:
Expand Down

0 comments on commit 32d3bef

Please sign in to comment.