From e242c86585e8cb44c1da9457ccdf8ab0a1e3f7ad Mon Sep 17 00:00:00 2001 From: mohammed Date: Thu, 3 Jul 2025 17:40:05 +0300 Subject: [PATCH] set the console.quiet in the __init__ --- codeflash/lsp/__init__.py | 4 ++++ codeflash/lsp/server.py | 13 +++++++------ codeflash/lsp/server_entry.py | 19 ++++++------------- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/codeflash/lsp/__init__.py b/codeflash/lsp/__init__.py index e69de29bb..9d75096ef 100644 --- a/codeflash/lsp/__init__.py +++ b/codeflash/lsp/__init__.py @@ -0,0 +1,4 @@ +# Silence the console module to prevent stdout pollution +from codeflash.cli_cmds.console import console + +console.quiet = True diff --git a/codeflash/lsp/server.py b/codeflash/lsp/server.py index 1a303c13c..a018786a8 100644 --- a/codeflash/lsp/server.py +++ b/codeflash/lsp/server.py @@ -3,7 +3,7 @@ from pathlib import Path from typing import TYPE_CHECKING, Any -from lsprotocol.types import INITIALIZE, MessageType, LogMessageParams +from lsprotocol.types import INITIALIZE, LogMessageParams, MessageType from pygls import uris from pygls.protocol import LanguageServerProtocol, lsp_method from pygls.server import LanguageServer @@ -58,21 +58,22 @@ def initialize_optimizer(self, config_file: Path) -> None: def show_message_log(self, message: str, message_type: str) -> None: """Send a log message to the client's output channel. - + Args: message: The message to log message_type: String type - "Info", "Warning", "Error", or "Log" + """ # Convert string message type to LSP MessageType enum type_mapping = { "Info": MessageType.Info, - "Warning": MessageType.Warning, + "Warning": MessageType.Warning, "Error": MessageType.Error, - "Log": MessageType.Log + "Log": MessageType.Log, } - + lsp_message_type = type_mapping.get(message_type, MessageType.Info) - + # Send log message to client (appears in output channel) log_params = LogMessageParams(type=lsp_message_type, message=message) self.lsp.notify("window/logMessage", log_params) diff --git a/codeflash/lsp/server_entry.py b/codeflash/lsp/server_entry.py index 841d18f84..b35e754ee 100644 --- a/codeflash/lsp/server_entry.py +++ b/codeflash/lsp/server_entry.py @@ -1,10 +1,9 @@ -"""This script is the dedicated entry point for the Codeflash Language Server. -It initializes the server and redirects its logs to stderr so that the -VS Code client can display them in the output channel. +# This script is the dedicated entry point for the Codeflash Language Server. +# It initializes the server and redirects its logs to stderr so that the +# VS Code client can display them in the output channel. -This script is run by the VS Code extension and is not intended to be -executed directly by users. -""" +# This script is run by the VS Code extension and is not intended to be +# executed directly by users. import logging import sys @@ -13,7 +12,7 @@ # Configure logging to stderr for VS Code output channel -def setup_logging(): +def setup_logging() -> logging.Logger: # Clear any existing handlers to prevent conflicts root_logger = logging.getLogger() root_logger.handlers.clear() @@ -38,11 +37,5 @@ def setup_logging(): log = setup_logging() log.info("Starting Codeflash Language Server...") - # Silence the console module to prevent stdout pollution - from codeflash.cli_cmds.console import console - - console.quiet = True - # console.enable() - # Start the language server server.start_io()