@@ -158,20 +158,6 @@ def initialize_function_optimization(
158158 return {"functionName" : params .functionName , "status" : "success" }
159159
160160
161- @server .feature ("discoverFunctionTests" )
162- def discover_function_tests (server : CodeflashLanguageServer , params : FunctionOptimizationParams ) -> dict [str , str ]:
163- fto = server .optimizer .current_function_being_optimized
164- optimizable_funcs = {fto .file_path : [fto ]}
165-
166- devnull_writer = open (os .devnull , "w" ) # noqa
167- with contextlib .redirect_stdout (devnull_writer ):
168- function_to_tests , num_discovered_tests = server .optimizer .discover_tests (optimizable_funcs )
169-
170- server .optimizer .discovered_tests = function_to_tests
171-
172- return {"functionName" : params .functionName , "status" : "success" , "discovered_tests" : num_discovered_tests }
173-
174-
175161@server .feature ("validateProject" )
176162def validate_project (server : CodeflashLanguageServer , _params : FunctionOptimizationParams ) -> dict [str , str ]:
177163 from codeflash .cli_cmds .cmd_init import is_valid_pyproject_toml
@@ -301,6 +287,12 @@ def perform_function_optimization( # noqa: PLR0911
301287 }
302288
303289 module_prep_result = server .optimizer .prepare_module_for_optimization (current_function .file_path )
290+ if not module_prep_result :
291+ return {
292+ "functionName" : params .functionName ,
293+ "status" : "error" ,
294+ "message" : "Failed to prepare module for optimization" ,
295+ }
304296
305297 validated_original_code , original_module_ast = module_prep_result
306298
@@ -309,7 +301,7 @@ def perform_function_optimization( # noqa: PLR0911
309301 function_to_optimize_source_code = validated_original_code [current_function .file_path ].source_code ,
310302 original_module_ast = original_module_ast ,
311303 original_module_path = current_function .file_path ,
312- function_to_tests = server . optimizer . discovered_tests or {},
304+ function_to_tests = {},
313305 )
314306
315307 server .optimizer .current_function_optimizer = function_optimizer
@@ -328,6 +320,13 @@ def perform_function_optimization( # noqa: PLR0911
328320 function_name = current_function .function_name ,
329321 )
330322
323+ optimizable_funcs = {current_function .file_path : [current_function ]}
324+
325+ devnull_writer = open (os .devnull , "w" ) # noqa
326+ with contextlib .redirect_stdout (devnull_writer ):
327+ function_to_tests , num_discovered_tests = server .optimizer .discover_tests (optimizable_funcs )
328+ function_optimizer .function_to_tests = function_to_tests
329+
331330 test_setup_result = function_optimizer .generate_and_instrument_tests (
332331 code_context , should_run_experiment = should_run_experiment
333332 )
0 commit comments