Skip to content

Commit

Permalink
Automatically hide the diagnostics panels on save
Browse files Browse the repository at this point in the history
  • Loading branch information
tdaniel22 committed Aug 30, 2022
1 parent eebaa3b commit a96e326
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions plugin/core/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions plugin/core/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 13 additions & 0 deletions plugin/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions tests/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down

0 comments on commit a96e326

Please sign in to comment.