Skip to content

Commit

Permalink
Print messages from window/logMessage into console instead of LSP log…
Browse files Browse the repository at this point in the history
… panel (#2444)

* Log messages from window/logMessage in console instead of log panel

* Add type hints
  • Loading branch information
jwortmann authored Apr 14, 2024
1 parent 550d591 commit f497d74
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
2 changes: 2 additions & 0 deletions plugin/core/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ class MessageType(IntEnum):
""" An information message. """
Log = 4
""" A log message. """
Debug = 5
""" A debug message. """


class TextDocumentSyncKind(IntEnum):
Expand Down
3 changes: 2 additions & 1 deletion plugin/core/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
19 changes: 17 additions & 2 deletions plugin/core/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit f497d74

Please sign in to comment.