Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print messages from window/logMessage into console instead of LSP log panel #2444

Merged
merged 2 commits into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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