From 32d3bef74016697caeeb5d5ff6a905814425203b Mon Sep 17 00:00:00 2001 From: Janos Wortmann Date: Mon, 23 Sep 2024 15:28:30 +0200 Subject: [PATCH] Delegate userprefs changes to Session -> SessionBuffer -> SessionView --- plugin/core/sessions.py | 24 +++++++++++++----------- plugin/core/windows.py | 8 +------- plugin/session_buffer.py | 13 ++++++++++--- plugin/session_view.py | 7 +++++-- 4 files changed, 29 insertions(+), 23 deletions(-) diff --git a/plugin/core/sessions.py b/plugin/core/sessions.py index 0ed01e315..f8932f8f5 100644 --- a/plugin/core/sessions.py +++ b/plugin/core/sessions.py @@ -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: ... @@ -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): @@ -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: @@ -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: ... @@ -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: ... @@ -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) @@ -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 diff --git a/plugin/core/windows.py b/plugin/core/windows.py index e5dc1a92e..f063b630d 100644 --- a/plugin/core/windows.py +++ b/plugin/core/windows.py @@ -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 diff --git a/plugin/session_buffer.py b/plugin/session_buffer.py index 5bdb7213d..09ee54a2e 100644 --- a/plugin/session_buffer.py +++ b/plugin/session_buffer.py @@ -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 @@ -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: @@ -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) diff --git a/plugin/session_view.py b/plugin/session_view.py index 7345ab5cc..febbe6fef 100644 --- a/plugin/session_view.py +++ b/plugin/session_view.py @@ -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 @@ -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: