From 218a2fce18c13707c700c9293ea243c59ed1b9fa Mon Sep 17 00:00:00 2001 From: Janos Wortmann Date: Sat, 13 Apr 2024 11:22:21 +0200 Subject: [PATCH 1/2] Log messages from window/logMessage in console instead of log panel --- plugin/core/protocol.py | 2 ++ plugin/core/windows.py | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/plugin/core/protocol.py b/plugin/core/protocol.py index 85f878800..25d4b8eb8 100644 --- a/plugin/core/protocol.py +++ b/plugin/core/protocol.py @@ -216,6 +216,8 @@ class MessageType(IntEnum): """ An information message. """ Log = 4 """ A log message. """ + Debug = 5 + """ A debug message. """ class TextDocumentSyncKind(IntEnum): diff --git a/plugin/core/windows.py b/plugin/core/windows.py index 80978f601..dd5b44d9b 100644 --- a/plugin/core/windows.py +++ b/plugin/core/windows.py @@ -14,6 +14,7 @@ from .panels import PanelName from .protocol import DocumentUri from .protocol import Error +from .protocol import MessageType from .sessions import AbstractViewListener from .sessions import get_plugin from .sessions import Logger @@ -414,7 +415,20 @@ def destroy(self) -> None: self.panel_manager = None def handle_log_message(self, session: Session, params: Any) -> None: - self.handle_server_message_async(session.config.name, extract_message(params)) + if not userprefs().log_debug: + return + message_type = params['type'] + level = { + MessageType.Error: "ERROR", + MessageType.Warning: "WARNING", + MessageType.Info: "INFO", + MessageType.Log: "LOG", + MessageType.Debug: "DEBUG" + }.get(message_type, "?") + message = params['message'] + print("{}: {}: {}".format(session.config.name, level, message)) + if message_type == MessageType.Error: + self.window.status_message("{}: {}".format(session.config.name, message)) def handle_stderr_log(self, session: Session, message: str) -> None: self.handle_server_message_async(session.config.name, message) From dd95c9fc113bccfb71e71b02c007a70929e3b989 Mon Sep 17 00:00:00 2001 From: Janos Wortmann Date: Sat, 13 Apr 2024 13:22:51 +0200 Subject: [PATCH 2/2] Add type hints --- plugin/core/sessions.py | 3 ++- plugin/core/windows.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plugin/core/sessions.py b/plugin/core/sessions.py index 70d6f8c77..0f660af8c 100644 --- a/plugin/core/sessions.py +++ b/plugin/core/sessions.py @@ -46,6 +46,7 @@ from .protocol import InsertTextMode from .protocol import Location from .protocol import LocationLink +from .protocol import LogMessageParams from .protocol import LSPAny from .protocol import LSPErrorCodes from .protocol import LSPObject @@ -1918,7 +1919,7 @@ def m_window_showMessage(self, params: Any) -> None: """handles the window/showMessage notification""" self.call_manager('handle_show_message', self, params) - def m_window_logMessage(self, params: Any) -> None: + def m_window_logMessage(self, params: LogMessageParams) -> None: """handles the window/logMessage notification""" self.call_manager('handle_log_message', self, params) diff --git a/plugin/core/windows.py b/plugin/core/windows.py index dd5b44d9b..662572e78 100644 --- a/plugin/core/windows.py +++ b/plugin/core/windows.py @@ -14,6 +14,7 @@ from .panels import PanelName from .protocol import DocumentUri from .protocol import Error +from .protocol import LogMessageParams from .protocol import MessageType from .sessions import AbstractViewListener from .sessions import get_plugin @@ -414,7 +415,7 @@ def destroy(self) -> None: self.panel_manager.destroy_output_panels() self.panel_manager = None - def handle_log_message(self, session: Session, params: Any) -> None: + def handle_log_message(self, session: Session, params: LogMessageParams) -> None: if not userprefs().log_debug: return message_type = params['type']