From 3423763749d7c8718ca52a583750100d75ac9818 Mon Sep 17 00:00:00 2001 From: Janos Wortmann Date: Wed, 7 Feb 2024 15:00:22 +0100 Subject: [PATCH] Remove hover provider count view setting --- plugin/core/constants.py | 1 - plugin/core/sessions.py | 1 + plugin/documents.py | 1 + plugin/hover.py | 5 ++--- plugin/session_view.py | 29 +++++++++++++---------------- 5 files changed, 17 insertions(+), 20 deletions(-) diff --git a/plugin/core/constants.py b/plugin/core/constants.py index 8d249e4aa..e8a84f34e 100644 --- a/plugin/core/constants.py +++ b/plugin/core/constants.py @@ -18,7 +18,6 @@ # Setting keys CODE_LENS_ENABLED_KEY = 'lsp_show_code_lens' HOVER_ENABLED_KEY = 'lsp_show_hover_popups' -HOVER_PROVIDER_COUNT_KEY = 'lsp_hover_provider_count' SHOW_DEFINITIONS_KEY = 'show_definitions' # Region flags diff --git a/plugin/core/sessions.py b/plugin/core/sessions.py index ab493525a..6cc789e07 100644 --- a/plugin/core/sessions.py +++ b/plugin/core/sessions.py @@ -679,6 +679,7 @@ class AbstractViewListener(metaclass=ABCMeta): TOTAL_ERRORS_AND_WARNINGS_STATUS_KEY = "lsp_total_errors_and_warnings" view = cast(sublime.View, None) + hover_provider_count = 0 @abstractmethod def session_async(self, capability: str, point: Optional[int] = None) -> Optional['Session']: diff --git a/plugin/documents.py b/plugin/documents.py index 71e97be1e..7f989153f 100644 --- a/plugin/documents.py +++ b/plugin/documents.py @@ -171,6 +171,7 @@ def on_change() -> None: self._completions_task = None # type: Optional[QueryCompletionsTask] self._stored_selection = [] # type: List[sublime.Region] self._should_format_on_paste = False + self.hover_provider_count = 0 self._setup() def __del__(self) -> None: diff --git a/plugin/hover.py b/plugin/hover.py index 51b72bdda..d91975028 100644 --- a/plugin/hover.py +++ b/plugin/hover.py @@ -3,7 +3,6 @@ from .code_actions import CodeActionsByConfigName from .core.constants import HOVER_ENABLED_KEY from .core.constants import HOVER_HIGHLIGHT_KEY -from .core.constants import HOVER_PROVIDER_COUNT_KEY from .core.constants import SHOW_DEFINITIONS_KEY from .core.open import lsp_range_from_uri_fragment from .core.open import open_file_uri @@ -22,7 +21,6 @@ from .core.sessions import SessionBufferProtocol from .core.settings import userprefs from .core.typing import List, Optional, Dict, Tuple, Sequence, Union -from .core.typing import cast from .core.url import parse_uri from .core.views import diagnostic_severity from .core.views import first_selection_region @@ -409,7 +407,8 @@ def run(self) -> None: sublime.set_timeout_async(partial(self._update_views_async, enable)) def _has_hover_provider(self, view: sublime.View) -> bool: - return cast(int, view.settings().get(HOVER_PROVIDER_COUNT_KEY, 0)) > 0 + listener = windows.listener_for_view(view) + return listener.hover_provider_count > 0 if listener else False def _update_views_async(self, enable: bool) -> None: window_manager = windows.lookup(self.window) diff --git a/plugin/session_view.py b/plugin/session_view.py index 2db34f094..3736fe9a4 100644 --- a/plugin/session_view.py +++ b/plugin/session_view.py @@ -4,7 +4,6 @@ from .core.constants import DOCUMENT_HIGHLIGHT_KIND_NAMES from .core.constants import HOVER_ENABLED_KEY from .core.constants import HOVER_HIGHLIGHT_KEY -from .core.constants import HOVER_PROVIDER_COUNT_KEY from .core.constants import REGIONS_INITIALIZE_FLAGS from .core.constants import SHOW_DEFINITIONS_KEY from .core.promise import Promise @@ -229,23 +228,21 @@ def _apply_auto_complete_triggers( settings.set(self.AC_TRIGGERS_KEY, triggers) def _increment_hover_count(self) -> None: - settings = self.view.settings() - count = settings.get(HOVER_PROVIDER_COUNT_KEY, 0) - if isinstance(count, int): - count += 1 - settings.set(HOVER_PROVIDER_COUNT_KEY, count) - window = self.view.window() - if window and window.settings().get(HOVER_ENABLED_KEY, True): - settings.set(SHOW_DEFINITIONS_KEY, False) + listener = self.listener() + if not listener: + return + listener.hover_provider_count += 1 + window = self.view.window() + if window and window.settings().get(HOVER_ENABLED_KEY, True): + self.view.settings().set(SHOW_DEFINITIONS_KEY, False) def _decrement_hover_count(self) -> None: - settings = self.view.settings() - count = settings.get(HOVER_PROVIDER_COUNT_KEY) - if isinstance(count, int): - count -= 1 - if count == 0: - settings.erase(HOVER_PROVIDER_COUNT_KEY) - self.reset_show_definitions() + listener = self.listener() + if not listener: + return + listener.hover_provider_count -= 1 + if listener.hover_provider_count == 0: + self.reset_show_definitions() def reset_show_definitions(self) -> None: self.view.settings().erase(SHOW_DEFINITIONS_KEY)