Skip to content

Commit d8a7255

Browse files
lsp silent logs
1 parent 02ae60b commit d8a7255

File tree

5 files changed

+24
-9
lines changed

5 files changed

+24
-9
lines changed

codeflash/cli_cmds/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def process_and_validate_cmd_args(args: Namespace) -> Namespace:
111111
from codeflash.code_utils.github_utils import require_github_app_or_exit
112112

113113
is_init: bool = args.command.startswith("init") if args.command else False
114-
if args.verbose:
114+
if args.verbose or is_LSP_enabled():
115115
logging_config.set_level(logging.DEBUG, echo_setting=not is_init)
116116
else:
117117
logging_config.set_level(logging.INFO, echo_setting=not is_init)

codeflash/cli_cmds/console.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
from codeflash.cli_cmds.console_constants import SPINNER_TYPES
2222
from codeflash.cli_cmds.logging_config import BARE_LOGGING_FORMAT
23+
from codeflash.lsp.helpers import lsp_log
2324

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

46+
real_info_log_fn = logger.info
47+
logger.info = lambda msg, *args, **kwargs: lsp_log(msg, real_info_log_fn, *args, **kwargs)
48+
49+
real_debug_log_fn = logger.debug
50+
logger.debug = lambda msg, *args, **kwargs: lsp_log(msg, real_debug_log_fn, *args, **kwargs)
51+
4552

4653
def paneled_text(
4754
text: str, panel_args: dict[str, str | bool] | None = None, text_args: dict[str, str] | None = None

codeflash/lsp/helpers.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
import os
22
from functools import lru_cache
3+
from typing import Any, Callable
34

45

56
@lru_cache(maxsize=1)
67
def is_LSP_enabled() -> bool:
78
return os.getenv("CODEFLASH_LSP", default="false").lower() == "true"
9+
10+
11+
def lsp_log(msg: str, actual_log_fn: Callable[[str, Any, Any], None], *args: Any, **kwargs: Any) -> None: # noqa: ANN401
12+
if is_LSP_enabled():
13+
actual_log_fn(f"::::{msg}", *args, **kwargs)
14+
else:
15+
actual_log_fn(msg, *args, **kwargs)

codeflash/lsp/server_entry.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,15 @@
1616
# Configure logging to stderr for VS Code output channel
1717
def setup_logging() -> logging.Logger:
1818
# Clear any existing handlers to prevent conflicts
19-
root_logger = logging.getLogger()
19+
root_logger = logging.getLogger("rich")
2020
root_logger.handlers.clear()
2121

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

2726
# Configure root logger
2827
root_logger.addHandler(handler)
29-
root_logger.setLevel(logging.INFO)
3028

3129
# Also configure the pygls logger specifically
3230
pygls_logger = logging.getLogger("pygls")

codeflash/optimization/function_optimizer.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,12 @@ def _process_refinement_results(self) -> OptimizedCandidate | None:
169169
for candidate in refinement_response:
170170
self.candidate_queue.put(candidate)
171171

172-
self.candidate_len += len(refinement_response)
173-
logger.info(
174-
f"Added {len(refinement_response)} candidates from refinement, total candidates now: {self.candidate_len}"
175-
)
172+
if len(refinement_response) > 0:
173+
self.candidate_len += len(refinement_response)
174+
logger.info(
175+
f"Added {len(refinement_response)} candidates from refinement, total candidates now: {self.candidate_len}"
176+
)
177+
176178
self.refinement_done = True
177179

178180
return self.get_next_candidate()

0 commit comments

Comments
 (0)