Skip to content

Commit 9f2d2c5

Browse files
committed
[Fix] Circular Import Bug
1 parent 376ca0d commit 9f2d2c5

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

codeflash/lsp/beta.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
get_functions_within_git_diff,
3030
)
3131
from codeflash.either import is_successful
32+
from codeflash.lsp.context import execution_context_vars
3233
from codeflash.lsp.features.perform_optimization import get_cancelled_reponse, sync_perform_optimization
3334
from codeflash.lsp.server import CodeflashLanguageServer, CodeflashLanguageServerProtocol
3435

@@ -336,12 +337,12 @@ def provide_api_key(params: ProvideApiKeyParams) -> dict[str, str]:
336337
def execution_context(**kwargs: str) -> None:
337338
"""Temporarily set context values for the current async task."""
338339
# Create a fresh copy per use
339-
current = {**server.execution_context_vars.get(), **kwargs}
340-
token = server.execution_context_vars.set(current)
340+
current = {**execution_context_vars.get(), **kwargs}
341+
token = execution_context_vars.set(current)
341342
try:
342343
yield
343344
finally:
344-
server.execution_context_vars.reset(token)
345+
execution_context_vars.reset(token)
345346

346347

347348
@server.feature("cleanupCurrentOptimizerSession")

codeflash/lsp/context.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from __future__ import annotations
2+
3+
import contextvars
4+
5+
# Shared execution context for tracking task IDs and other metadata
6+
execution_context_vars: contextvars.ContextVar[dict[str, str]] = contextvars.ContextVar(
7+
"execution_context_vars",
8+
default={}, # noqa: B039
9+
)

codeflash/lsp/lsp_message.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ def type(self) -> str:
4444
def serialize(self) -> str:
4545
if not is_LSP_enabled():
4646
return ""
47-
from codeflash.lsp.beta import server
47+
from codeflash.lsp.context import execution_context_vars
4848

49-
execution_ctx = server.execution_context_vars.get()
49+
execution_ctx = execution_context_vars.get()
5050
current_task_id = execution_ctx.get("task_id", None)
5151
data = self._loop_through(asdict(self))
5252
ordered = {"type": self.type(), "task_id": current_task_id, **data}

codeflash/lsp/server.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
import contextvars
43
from typing import TYPE_CHECKING
54

65
from lsprotocol.types import LogMessageParams, MessageType
@@ -25,10 +24,6 @@ def __init__(self, name: str, version: str, protocol_cls: type[LanguageServerPro
2524
self.optimizer: Optimizer | None = None
2625
self.args = None
2726
self.current_optimization_init_result: tuple[bool, CodeOptimizationContext, dict[Path, str]] | None = None
28-
self.execution_context_vars: contextvars.ContextVar[dict[str, str]] = contextvars.ContextVar(
29-
"execution_context_vars",
30-
default={}, # noqa: B039
31-
)
3227

3328
def prepare_optimizer_arguments(self, config_file: Path) -> None:
3429
from codeflash.cli_cmds.cli import parse_args

0 commit comments

Comments
 (0)