Skip to content

Commit

Permalink
moved notification logging functions to a separate file to avoid circ…
Browse files Browse the repository at this point in the history
…ular imports
  • Loading branch information
eugenesvk committed Nov 27, 2024
1 parent d0e8f16 commit 6bbced9
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 36 deletions.
2 changes: 1 addition & 1 deletion plugin/code_actions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import annotations
from .core.logging import notify_error
from .core.logging_notify import notify_error
from .core.promise import Promise
from .core.protocol import CodeAction
from .core.protocol import CodeActionKind
Expand Down
30 changes: 1 addition & 29 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, Optional
from typing import Any
import traceback
import inspect
import sublime
Expand Down Expand Up @@ -39,31 +39,3 @@ def exception_log(message: str, ex: Exception) -> None:
def printf(*args: Any, prefix: str = 'LSP') -> None:
"""Print args to the console, prefixed by the plugin name."""
print(prefix + ":", *args)


def notify(window: sublime.Window | None, message: str, status_message: 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 not window:
return
if userprefs().suppress_error_dialogs:
window.status_message(status_message)
print(message)
else:
sublime.message_dialog(message)


def notify_error(window: sublime.Window | None, message: str, status_message: 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 not window:
return
if userprefs().suppress_error_dialogs:
window.status_message(status_message)
print(message)
else:
sublime.error_message(message)
29 changes: 29 additions & 0 deletions plugin/core/logging_notify.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from __future__ import annotations
import sublime
from .settings import userprefs


def notify(window: sublime.Window | None, message: str, status_message: 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"""
if not window:
return
if userprefs().suppress_error_dialogs:
window.status_message(status_message)
print(message)
else:
sublime.message_dialog(message)


def notify_error(window: sublime.Window | None, message: str, status_message: 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"""
if not window:
return
if userprefs().suppress_error_dialogs:
window.status_message(status_message)
print(message)
else:
sublime.error_message(message)
2 changes: 1 addition & 1 deletion plugin/core/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from .diagnostics_storage import is_severity_included
from .logging import debug
from .logging import exception_log
from .logging import notify
from .logging_notify import notify
from .message_request_handler import MessageRequestHandler
from .panels import LOG_LINES_LIMIT_SETTING_NAME
from .panels import MAX_LOG_LINES_LIMIT_OFF
Expand Down
2 changes: 1 addition & 1 deletion plugin/core/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from .types import matches_pattern
from .types import sublime_pattern_to_glob
from .url import filename_to_uri
from .logging import notify
from .logging_notify import notify
from typing import Any
import sublime
import os
Expand Down
2 changes: 1 addition & 1 deletion plugin/execute_command.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import annotations
from .core.logging import notify
from .core.logging_notify import notify
from .core.protocol import Error
from .core.protocol import ExecuteCommandParams
from .core.registry import LspTextCommand
Expand Down
2 changes: 1 addition & 1 deletion plugin/rename.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from .core.edit import parse_range
from .core.edit import parse_workspace_edit
from .core.edit import WorkspaceChanges
from .core.logging import notify_error
from .core.logging_notify import notify_error
from .core.protocol import PrepareRenameParams
from .core.protocol import PrepareRenameResult
from .core.protocol import Range
Expand Down
4 changes: 2 additions & 2 deletions plugin/tooling.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from __future__ import annotations
from .core.css import css
from .core.logging import debug
from .core.logging import notify
from .core.logging import notify_error
from .core.logging_notify import notify
from .core.logging_notify import notify_error
from .core.registry import windows
from .core.sessions import get_plugin
from .core.transports import create_transport
Expand Down

0 comments on commit 6bbced9

Please sign in to comment.