From a96e3260f07f38f6045e3ad41f3a9b7057c38b18 Mon Sep 17 00:00:00 2001 From: Tristan Daniel Date: Tue, 30 Aug 2022 23:38:05 +0200 Subject: [PATCH] Automatically hide the diagnostics panels on save Resolves #1904 --- plugin/core/sessions.py | 4 ++++ plugin/core/windows.py | 4 ++++ plugin/documents.py | 13 +++++++++++++ tests/test_session.py | 3 +++ 4 files changed, 24 insertions(+) diff --git a/plugin/core/sessions.py b/plugin/core/sessions.py index 4c5ee436e..be35c3a56 100644 --- a/plugin/core/sessions.py +++ b/plugin/core/sessions.py @@ -176,6 +176,10 @@ def update_diagnostics_panel_async(self) -> None: def show_diagnostics_panel_async(self) -> None: pass + @abstractmethod + def hide_diagnostics_panel_async(self) -> None: + pass + # Event callbacks @abstractmethod diff --git a/plugin/core/windows.py b/plugin/core/windows.py index f6463719d..4256f059c 100644 --- a/plugin/core/windows.py +++ b/plugin/core/windows.py @@ -464,6 +464,10 @@ def show_diagnostics_panel_async(self) -> None: if self._window.active_panel() is None: self._window.run_command("show_panel", {"panel": "output.diagnostics"}) + def hide_diagnostics_panel_async(self) -> None: + if self._window.active_panel() == "output.diagnostics": + self._window.run_command("hide_panel", {"panel": "output.diagnostics"}) + class WindowRegistry(object): def __init__(self, configs: ConfigManager) -> None: diff --git a/plugin/documents.py b/plugin/documents.py index 784ef4523..e36f3fcdd 100644 --- a/plugin/documents.py +++ b/plugin/documents.py @@ -383,6 +383,19 @@ def on_post_save_async(self) -> None: # The URI scheme has changed. This means we need to re-determine whether any language servers should # be attached to the view. sublime.set_timeout(self._reset) + # Hide empty diagnostics panels on save if the show_diagnostics_panel_on_save option is enabled. + if userprefs().show_diagnostics_panel_on_save > 0: + self._hide_empty_diagnostics_panels() + + def _hide_empty_diagnostics_panels(self) -> None: + severity_threshold = userprefs().show_diagnostics_severity_level + hide_panel = True + for sb, diagnostics in self.diagnostics_async(): + for diagnostic, _ in diagnostics: + if diagnostic_severity(diagnostic) <= severity_threshold: + hide_panel = False + if hide_panel and self._manager: + self._manager.hide_diagnostics_panel_async() def on_close(self) -> None: if self._registered and self._manager: diff --git a/tests/test_session.py b/tests/test_session.py index a54780caf..e0ba8aa65 100644 --- a/tests/test_session.py +++ b/tests/test_session.py @@ -48,6 +48,9 @@ def update_diagnostics_panel_async(self) -> None: def show_diagnostics_panel_async(self) -> None: pass + def hide_diagnostics_panel_async(self) -> None: + pass + class MockLogger(Logger):