Skip to content

Commit

Permalink
Automatically hide the diagnostics panels on save
Browse files Browse the repository at this point in the history
Resolves #1904
  • Loading branch information
tdaniel22 committed Aug 30, 2022
1 parent eebaa3b commit 6563d3e
Show file tree
Hide file tree
Showing 4 changed files with 22 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
11 changes: 11 additions & 0 deletions plugin/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,17 @@ 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:
change_count = self.view.change_count()
for sb in self.session_buffers_async():
if sb.diagnostics_version != change_count or not sb.diagnostics:
mgr = sb.session.manager()
if mgr:
mgr.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 6563d3e

Please sign in to comment.