Skip to content

Commit

Permalink
accept optional sublime Window in notify functions
Browse files Browse the repository at this point in the history
fallback sublime functions
  • Loading branch information
eugenesvk committed Nov 7, 2024
1 parent 360c41a commit d9dc495
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions plugin/core/logging.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import annotations
from typing import Any
from typing import Any, Optional
import traceback
import inspect
import sublime
Expand Down Expand Up @@ -41,25 +41,33 @@ def printf(*args: Any, prefix: str = 'LSP') -> None:
print(prefix + ":", *args)


def notify(window: sublime.Window, message: str, status: str = 'LSP: see console log…') -> None:
"""Pick either of the 2 ways to show a message:
- via a blocking modal dialog
- via a detailed console message and a short status message"""
def notify(window: Optional[sublime.Window], message: str,
status: str = 'LSP: see console log…') -> None:
"""Pick either of the 2 ways to show a user notification message:
- via a detailed console message and a short status message
- via a blocking modal dialog"""
from .settings import userprefs
if userprefs().suppress_error_dialogs:
window.status_message(status)
print(message)
if window:
window.status_message(status) # print short message to statusbar
else:
sublime.status_message(status)
print(message) # print full message to console log
else:
window.message_dialog(message)
sublime.message_dialog(message)


def notify_error(window: sublime.Window, message: str, status: str = '❗LSP: see console log…') -> None:
"""Pick either of the 2 ways to show a message:
- via a blocking modal dialog
- via a detailed console message and a short status message"""
def notify_error(window: Optional[sublime.Window], message: str,
status: str = '❗LSP: see console log…') -> None:
"""Pick either of the 2 ways to show a user error notification message:
- via a detailed console message and a short status message
- via a blocking error modal dialog"""
from .settings import userprefs
if userprefs().suppress_error_dialogs:
window.status_message(status)
print(message)
if window:
window.status_message(status) # print short message to statusbar
else:
sublime.status_message(status)
print(message) # print full message to console log
else:
sublime.error_message(message)

0 comments on commit d9dc495

Please sign in to comment.