77from pathlib import Path
88from typing import TYPE_CHECKING , Optional
99
10- from pygls import uris
11-
1210from codeflash .api .cfapi import get_codeflash_api_key , get_user_id
1311from codeflash .cli_cmds .cli import process_pyproject_config
1412from codeflash .cli_cmds .cmd_init import (
@@ -128,7 +126,11 @@ def _group_functions_by_file(
128126def get_optimizable_functions (
129127 server : CodeflashLanguageServer , params : OptimizableFunctionsParams
130128) -> dict [str , list [str ]]:
131- file_path = Path (uris .to_fs_path (params .textDocument .uri ))
129+ document_uri = params .textDocument .uri
130+ document = server .workspace .get_text_document (document_uri )
131+
132+ file_path = Path (document .path )
133+
132134 if not server .optimizer :
133135 return {"status" : "error" , "message" : "optimizer not initialized" }
134136
@@ -321,8 +323,10 @@ def provide_api_key(server: CodeflashLanguageServer, params: ProvideApiKeyParams
321323def initialize_function_optimization (
322324 server : CodeflashLanguageServer , params : FunctionOptimizationInitParams
323325) -> dict [str , str ]:
324- file_path = Path (uris .to_fs_path (params .textDocument .uri ))
325- server .show_message_log (f"Initializing optimization for function: { params .functionName } in { file_path } " , "Info" )
326+ document_uri = params .textDocument .uri
327+ document = server .workspace .get_text_document (document_uri )
328+
329+ server .show_message_log (f"Initializing optimization for function: { params .functionName } in { document_uri } " , "Info" )
326330
327331 if server .optimizer is None :
328332 _initialize_optimizer_if_api_key_is_valid (server )
@@ -332,7 +336,7 @@ def initialize_function_optimization(
332336 original_args , _ = server .optimizer .original_args_and_test_cfg
333337
334338 server .optimizer .args .function = params .functionName
335- original_relative_file_path = file_path .relative_to (original_args .project_root )
339+ original_relative_file_path = Path ( document . path ) .relative_to (original_args .project_root )
336340 server .optimizer .args .file = server .optimizer .current_worktree / original_relative_file_path
337341 server .optimizer .args .previous_checkpoint_functions = False
338342
0 commit comments