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/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 80978f601..662572e78 100644 --- a/plugin/core/windows.py +++ b/plugin/core/windows.py @@ -14,6 +14,8 @@ 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 from .sessions import Logger @@ -413,8 +415,21 @@ def destroy(self) -> None: self.panel_manager.destroy_output_panels() 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)) + def handle_log_message(self, session: Session, params: LogMessageParams) -> None: + 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)