From 6bbced9dd154a0e0cb3e4ad2147a31df03c1f3fa Mon Sep 17 00:00:00 2001 From: eugenesvk Date: Wed, 27 Nov 2024 13:25:07 +0700 Subject: [PATCH] moved notification logging functions to a separate file to avoid circular imports --- plugin/code_actions.py | 2 +- plugin/core/logging.py | 30 +----------------------------- plugin/core/logging_notify.py | 29 +++++++++++++++++++++++++++++ plugin/core/windows.py | 2 +- plugin/core/workspace.py | 2 +- plugin/execute_command.py | 2 +- plugin/rename.py | 2 +- plugin/tooling.py | 4 ++-- 8 files changed, 37 insertions(+), 36 deletions(-) create mode 100644 plugin/core/logging_notify.py diff --git a/plugin/code_actions.py b/plugin/code_actions.py index e9f3a19c5..86bd87db4 100644 --- a/plugin/code_actions.py +++ b/plugin/code_actions.py @@ -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 diff --git a/plugin/core/logging.py b/plugin/core/logging.py index 0fbf7006e..ebaeb3629 100644 --- a/plugin/core/logging.py +++ b/plugin/core/logging.py @@ -1,5 +1,5 @@ from __future__ import annotations -from typing import Any, Optional +from typing import Any import traceback import inspect import sublime @@ -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) diff --git a/plugin/core/logging_notify.py b/plugin/core/logging_notify.py new file mode 100644 index 000000000..746391814 --- /dev/null +++ b/plugin/core/logging_notify.py @@ -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) diff --git a/plugin/core/windows.py b/plugin/core/windows.py index dd7e8af65..a5d0f1d63 100644 --- a/plugin/core/windows.py +++ b/plugin/core/windows.py @@ -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 diff --git a/plugin/core/workspace.py b/plugin/core/workspace.py index b63cdf6b3..31d7b92c7 100644 --- a/plugin/core/workspace.py +++ b/plugin/core/workspace.py @@ -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 diff --git a/plugin/execute_command.py b/plugin/execute_command.py index 50c456ee8..89cb2393a 100644 --- a/plugin/execute_command.py +++ b/plugin/execute_command.py @@ -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 diff --git a/plugin/rename.py b/plugin/rename.py index 183a87b2d..7bc16bd76 100644 --- a/plugin/rename.py +++ b/plugin/rename.py @@ -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 diff --git a/plugin/tooling.py b/plugin/tooling.py index aa1a982fd..617ff7317 100644 --- a/plugin/tooling.py +++ b/plugin/tooling.py @@ -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