From 9097bd1689105922ab1aa439997933fa03a24614 Mon Sep 17 00:00:00 2001 From: Janos Wortmann Date: Sat, 12 Oct 2024 14:41:01 +0200 Subject: [PATCH 1/2] Remove unnecessary parallel debouncing --- plugin/documents.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/plugin/documents.py b/plugin/documents.py index 4ae268c83..bbf5827be 100644 --- a/plugin/documents.py +++ b/plugin/documents.py @@ -139,9 +139,7 @@ def __repr__(self) -> str: class DocumentSyncListener(sublime_plugin.ViewEventListener, AbstractViewListener): ACTIVE_DIAGNOSTIC = "lsp_active_diagnostic" - code_actions_debounce_time = FEATURES_TIMEOUT color_boxes_debounce_time = FEATURES_TIMEOUT - highlights_debounce_time = FEATURES_TIMEOUT code_lenses_debounce_time = FEATURES_TIMEOUT @classmethod @@ -388,16 +386,19 @@ def on_selection_modified_async(self) -> None: return if not self._is_in_higlighted_region(first_region.b): self._clear_highlight_regions() - if userprefs().document_highlight_style: - self._when_selection_remains_stable_async(self._do_highlights_async, first_region, - after_ms=self.highlights_debounce_time) self._clear_code_actions_annotation() - if userprefs().show_code_actions: - self._when_selection_remains_stable_async(self._do_code_actions_async, first_region, - after_ms=self.code_actions_debounce_time) + if userprefs().document_highlight_style or userprefs().show_code_actions: + self._when_selection_remains_stable_async( + self._on_selection_modified_debounced_async, first_region, after_ms=FEATURES_TIMEOUT) self._update_diagnostic_in_status_bar_async() self._resolve_visible_code_lenses_async() + def _on_selection_modified_debounced_async(self) -> None: + if userprefs().document_highlight_style: + self._do_highlights_async() + if userprefs().show_code_actions: + self._do_code_actions_async() + def on_post_save_async(self) -> None: # Re-determine the URI; this time it's guaranteed to be a file because ST can only save files to a real # filesystem. @@ -952,7 +953,7 @@ def _on_view_updated_async(self) -> None: self._clear_highlight_regions() if userprefs().document_highlight_style: self._when_selection_remains_stable_async( - self._do_highlights_async, first_region, after_ms=self.highlights_debounce_time) + self._do_highlights_async, first_region, after_ms=FEATURES_TIMEOUT) self.do_signature_help_async(manual=False) def _update_stored_selection_async(self) -> tuple[sublime.Region | None, bool]: From 7a52b16eea007661e9a69b9c74e9fd7d7f4b2356 Mon Sep 17 00:00:00 2001 From: Janos Wortmann Date: Sat, 12 Oct 2024 15:15:49 +0200 Subject: [PATCH 2/2] Update tests --- plugin/documents.py | 5 +++-- tests/test_code_actions.py | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/plugin/documents.py b/plugin/documents.py index bbf5827be..a08658d0a 100644 --- a/plugin/documents.py +++ b/plugin/documents.py @@ -139,6 +139,7 @@ def __repr__(self) -> str: class DocumentSyncListener(sublime_plugin.ViewEventListener, AbstractViewListener): ACTIVE_DIAGNOSTIC = "lsp_active_diagnostic" + debounce_time = FEATURES_TIMEOUT color_boxes_debounce_time = FEATURES_TIMEOUT code_lenses_debounce_time = FEATURES_TIMEOUT @@ -389,7 +390,7 @@ def on_selection_modified_async(self) -> None: self._clear_code_actions_annotation() if userprefs().document_highlight_style or userprefs().show_code_actions: self._when_selection_remains_stable_async( - self._on_selection_modified_debounced_async, first_region, after_ms=FEATURES_TIMEOUT) + self._on_selection_modified_debounced_async, first_region, after_ms=self.debounce_time) self._update_diagnostic_in_status_bar_async() self._resolve_visible_code_lenses_async() @@ -953,7 +954,7 @@ def _on_view_updated_async(self) -> None: self._clear_highlight_regions() if userprefs().document_highlight_style: self._when_selection_remains_stable_async( - self._do_highlights_async, first_region, after_ms=FEATURES_TIMEOUT) + self._do_highlights_async, first_region, after_ms=self.debounce_time) self.do_signature_help_async(manual=False) def _update_stored_selection_async(self) -> tuple[sublime.Region | None, bool]: diff --git a/tests/test_code_actions.py b/tests/test_code_actions.py index 7932d6004..dec107784 100644 --- a/tests/test_code_actions.py +++ b/tests/test_code_actions.py @@ -269,11 +269,11 @@ def test_kind_matching(self) -> None: class CodeActionsListenerTestCase(TextDocumentTestCase): def setUp(self) -> Generator: yield from super().setUp() - self.original_debounce_time = DocumentSyncListener.code_actions_debounce_time - DocumentSyncListener.code_actions_debounce_time = 0 + self.original_debounce_time = DocumentSyncListener.debounce_time + DocumentSyncListener.debounce_time = 0 def tearDown(self) -> None: - DocumentSyncListener.code_actions_debounce_time = self.original_debounce_time + DocumentSyncListener.debounce_time = self.original_debounce_time super().tearDown() @classmethod