Skip to content
Draft
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: 1 addition & 1 deletion codeflash/cli_cmds/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def process_and_validate_cmd_args(args: Namespace) -> Namespace:
from codeflash.code_utils.github_utils import require_github_app_or_exit

is_init: bool = args.command.startswith("init") if args.command else False
if args.verbose:
if args.verbose or is_LSP_enabled():
logging_config.set_level(logging.DEBUG, echo_setting=not is_init)
else:
logging_config.set_level(logging.INFO, echo_setting=not is_init)
Expand Down
7 changes: 7 additions & 0 deletions codeflash/cli_cmds/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

from codeflash.cli_cmds.console_constants import SPINNER_TYPES
from codeflash.cli_cmds.logging_config import BARE_LOGGING_FORMAT
from codeflash.lsp.helpers import lsp_log

if TYPE_CHECKING:
from collections.abc import Generator
Expand All @@ -42,6 +43,12 @@
logger = logging.getLogger("rich")
logging.getLogger("parso").setLevel(logging.WARNING)

real_info_log_fn = logger.info
logger.info = lambda msg, *args, **kwargs: lsp_log(msg, real_info_log_fn, *args, **kwargs)

real_debug_log_fn = logger.debug
logger.debug = lambda msg, *args, **kwargs: lsp_log(msg, real_debug_log_fn, *args, **kwargs)


def paneled_text(
text: str, panel_args: dict[str, str | bool] | None = None, text_args: dict[str, str] | None = None
Expand Down
8 changes: 8 additions & 0 deletions codeflash/lsp/helpers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import os
from functools import lru_cache
from typing import Any, Callable


@lru_cache(maxsize=1)
def is_LSP_enabled() -> bool:
return os.getenv("CODEFLASH_LSP", default="false").lower() == "true"


def lsp_log(msg: str, actual_log_fn: Callable[[str, Any, Any], None], *args: Any, **kwargs: Any) -> None: # noqa: ANN401
if is_LSP_enabled():
actual_log_fn(f"::::{msg}", *args, **kwargs)
else:
actual_log_fn(msg, *args, **kwargs)
6 changes: 2 additions & 4 deletions codeflash/lsp/server_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,15 @@
# Configure logging to stderr for VS Code output channel
def setup_logging() -> logging.Logger:
# Clear any existing handlers to prevent conflicts
root_logger = logging.getLogger()
root_logger = logging.getLogger("rich")
root_logger.handlers.clear()

# Set up stderr handler for VS Code output channel with [LSP-Server] prefix
handler = logging.StreamHandler(sys.stderr)
# adding the :::: here for the client to easily extract the message from the log
handler.setFormatter(logging.Formatter("[LSP-Server] %(asctime)s [%(levelname)s]::::%(message)s"))
handler.setLevel(logging.DEBUG)

# Configure root logger
root_logger.addHandler(handler)
root_logger.setLevel(logging.INFO)

# Also configure the pygls logger specifically
pygls_logger = logging.getLogger("pygls")
Expand Down
10 changes: 6 additions & 4 deletions codeflash/optimization/function_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,12 @@ def _process_refinement_results(self) -> OptimizedCandidate | None:
for candidate in refinement_response:
self.candidate_queue.put(candidate)

self.candidate_len += len(refinement_response)
logger.info(
f"Added {len(refinement_response)} candidates from refinement, total candidates now: {self.candidate_len}"
)
if len(refinement_response) > 0:
self.candidate_len += len(refinement_response)
logger.info(
f"Added {len(refinement_response)} candidates from refinement, total candidates now: {self.candidate_len}"
)

self.refinement_done = True

return self.get_next_candidate()
Expand Down
Loading