Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically hide the diagnostics panel on save #2037

Merged
merged 3 commits into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
rchl marked this conversation as resolved.
Show resolved Hide resolved

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
rchl marked this conversation as resolved.
Show resolved Hide resolved
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