Skip to content

Commit 546a8df

Browse files
committed
consolidate error notification into 1 function
with an extra severe argument to downgrade to a non-error modal dialog if needed
1 parent 5ab0e73 commit 546a8df

File tree

5 files changed

+15
-26
lines changed

5 files changed

+15
-26
lines changed

plugin/core/logging_notify.py

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,18 @@
22
import sublime
33
from .settings import userprefs
44

5-
6-
def notify(window: sublime.Window | None, message: str, status_message: str = 'LSP: see console log…') -> None:
7-
"""Pick either of the 2 ways to show a user notification message:
8-
- via a detailed console message and a short status message
9-
- via a blocking modal dialog"""
10-
if not window:
11-
return
12-
if userprefs().suppress_error_dialogs:
13-
window.status_message(status_message)
14-
print(message)
15-
else:
16-
sublime.message_dialog(message)
17-
18-
19-
def notify_error(window: sublime.Window | None, message: str, status_message: str = '❗LSP: see console log…') -> None:
5+
def notify_error(window: sublime.Window | None, message: str, status_message: str = 'LSP: see console log…',
6+
severe: bool = True) -> None:
207
"""Pick either of the 2 ways to show a user error notification message:
218
- via a detailed console message and a short status message
22-
- via a blocking error modal dialog"""
9+
- via a blocking error modal dialog (with severe=false non-error modal dialog)"""
2310
if not window:
2411
return
2512
if userprefs().suppress_error_dialogs:
2613
window.status_message(status_message)
2714
print(message)
2815
else:
29-
sublime.error_message(message)
16+
if severe:
17+
sublime.error_message(message)
18+
else:
19+
sublime.message_dialog(message)

plugin/core/windows.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from .diagnostics_storage import is_severity_included
88
from .logging import debug
99
from .logging import exception_log
10-
from .logging_notify import notify
10+
from .logging_notify import notify_error
1111
from .message_request_handler import MessageRequestHandler
1212
from .panels import LOG_LINES_LIMIT_SETTING_NAME
1313
from .panels import MAX_LOG_LINES_LIMIT_OFF
@@ -302,7 +302,7 @@ def start_async(self, config: ClientConfig, initiating_view: sublime.View) -> No
302302
print("Server output:\n{}".format(e.output.decode('utf-8', 'replace')))
303303
self._config_manager.disable_config(config.name, only_for_session=True)
304304
config.erase_view_status(initiating_view)
305-
notify(self._window, message, status)
305+
notify_error(self._window, message, status)
306306
# Continue with handling pending listeners
307307
self._new_session = None
308308
sublime.set_timeout_async(self._dequeue_listener_async)

plugin/core/workspace.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from .types import matches_pattern
55
from .types import sublime_pattern_to_glob
66
from .url import filename_to_uri
7-
from .logging_notify import notify
7+
from .logging_notify import notify_error
88
from typing import Any
99
import sublime
1010
import os
@@ -149,7 +149,7 @@ def enable_in_project(window: sublime.Window, config_name: str) -> None:
149149
else:
150150
message = f"Can't enable {config_name} in the current workspace. Ensure that the project is saved first."
151151
status = f"Can't enable {config_name} in this workspace… See console"
152-
notify(window, message, status)
152+
notify_error(window, message, status)
153153

154154

155155
def disable_in_project(window: sublime.Window, config_name: str) -> None:
@@ -163,4 +163,4 @@ def disable_in_project(window: sublime.Window, config_name: str) -> None:
163163
else:
164164
message = f"Can't disable {config_name} in the current workspace. Ensure that the project is saved first."
165165
status = f"Can't enable {config_name} in this workspace… See console"
166-
notify(window, message, status)
166+
notify_error(window, message, status)

plugin/execute_command.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from __future__ import annotations
2-
from .core.logging_notify import notify
2+
from .core.logging_notify import notify_error
33
from .core.protocol import Error
44
from .core.protocol import ExecuteCommandParams
55
from .core.registry import LspTextCommand
@@ -61,7 +61,7 @@ def handle_error_async(self, error: Error, command_name: str) -> None:
6161
"""
6262
message = f"command {command_name} failed. Reason: {str(error)}"
6363
status = f"{command_name} failed… See console"
64-
notify(self.view.window(), message, status)
64+
notify_error(self.view.window(), message, status)
6565

6666
def _expand_variables(self, command_args: list[Any]) -> list[Any]:
6767
view = self.view

plugin/tooling.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import annotations
22
from .core.css import css
33
from .core.logging import debug
4-
from .core.logging_notify import notify
54
from .core.logging_notify import notify_error
65
from .core.registry import windows
76
from .core.sessions import get_plugin
@@ -313,7 +312,7 @@ def run(self) -> None:
313312
view = wm.window.active_view()
314313
if not view:
315314
message = 'Troubleshooting must be run with a file opened'
316-
notify(self.window, message, message)
315+
notify_error(self.window, message, message)
317316
return
318317
active_view = view
319318
configs = wm.get_config_manager().get_configs()

0 commit comments

Comments
 (0)