Skip to content

Commit 4066c9a

Browse files
Merge pull request #840 from codeflash-ai/pygls/v2
Migrate pygls to v2
2 parents 9223252 + 5280484 commit 4066c9a

File tree

4 files changed

+21
-16
lines changed

4 files changed

+21
-16
lines changed

codeflash/lsp/beta.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
from pathlib import Path
77
from typing import TYPE_CHECKING, Optional
88

9-
from pygls import uris
10-
119
from codeflash.api.cfapi import get_codeflash_api_key, get_user_id
1210
from codeflash.cli_cmds.cli import process_pyproject_config
1311
from codeflash.code_utils.git_utils import git_root_dir
@@ -111,7 +109,11 @@ def _group_functions_by_file(
111109
def get_optimizable_functions(
112110
server: CodeflashLanguageServer, params: OptimizableFunctionsParams
113111
) -> dict[str, list[str]]:
114-
file_path = Path(uris.to_fs_path(params.textDocument.uri))
112+
document_uri = params.textDocument.uri
113+
document = server.workspace.get_text_document(document_uri)
114+
115+
file_path = Path(document.path)
116+
115117
if not server.optimizer:
116118
return {"status": "error", "message": "optimizer not initialized"}
117119

@@ -264,8 +266,10 @@ def provide_api_key(server: CodeflashLanguageServer, params: ProvideApiKeyParams
264266
def initialize_function_optimization(
265267
server: CodeflashLanguageServer, params: FunctionOptimizationInitParams
266268
) -> dict[str, str]:
267-
file_path = Path(uris.to_fs_path(params.textDocument.uri))
268-
server.show_message_log(f"Initializing optimization for function: {params.functionName} in {file_path}", "Info")
269+
document_uri = params.textDocument.uri
270+
document = server.workspace.get_text_document(document_uri)
271+
272+
server.show_message_log(f"Initializing optimization for function: {params.functionName} in {document_uri}", "Info")
269273

270274
if server.optimizer is None:
271275
_initialize_optimizer_if_api_key_is_valid(server)
@@ -275,7 +279,7 @@ def initialize_function_optimization(
275279
original_args, _ = server.optimizer.original_args_and_test_cfg
276280

277281
server.optimizer.args.function = params.functionName
278-
original_relative_file_path = file_path.relative_to(original_args.project_root)
282+
original_relative_file_path = Path(document.path).relative_to(original_args.project_root)
279283
server.optimizer.args.file = server.optimizer.current_worktree / original_relative_file_path
280284
server.optimizer.args.previous_checkpoint_functions = False
281285

codeflash/lsp/server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
from typing import TYPE_CHECKING, Any
44

55
from lsprotocol.types import LogMessageParams, MessageType
6+
from pygls.lsp.server import LanguageServer
67
from pygls.protocol import LanguageServerProtocol
7-
from pygls.server import LanguageServer
88

99
if TYPE_CHECKING:
1010
from pathlib import Path
@@ -56,7 +56,7 @@ def show_message_log(self, message: str, message_type: str) -> None:
5656

5757
# Send log message to client (appears in output channel)
5858
log_params = LogMessageParams(type=lsp_message_type, message=message)
59-
self.lsp.notify("window/logMessage", log_params)
59+
self.protocol.notify("window/logMessage", log_params)
6060

6161
def cleanup_the_optimizer(self) -> None:
6262
self.current_optimization_init_result = None

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ dependencies = [
4141
"coverage>=7.6.4",
4242
"line_profiler>=4.2.0",
4343
"platformdirs>=4.3.7",
44-
"pygls>=1.3.1",
44+
"pygls>=2.0.0,<3.0.0",
4545
"codeflash-benchmark",
4646
"filelock",
4747
]

uv.lock

Lines changed: 8 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)