@@ -37,28 +37,30 @@ def get_optimizable_functions(
3737) -> dict [str , list [str ]]:
3838 file_path = Path (uris .to_fs_path (params .textDocument .uri ))
3939 server .show_message_log (f"Getting optimizable functions for: { file_path } " , "Info" )
40-
40+
4141 # Save original args to restore later
42- original_file = getattr (server .optimizer .args , ' file' , None )
43- original_function = getattr (server .optimizer .args , ' function' , None )
44- original_checkpoint = getattr (server .optimizer .args , ' previous_checkpoint_functions' , None )
45-
42+ original_file = getattr (server .optimizer .args , " file" , None )
43+ original_function = getattr (server .optimizer .args , " function" , None )
44+ original_checkpoint = getattr (server .optimizer .args , " previous_checkpoint_functions" , None )
45+
4646 server .show_message_log (f"Original args - file: { original_file } , function: { original_function } " , "Info" )
47-
47+
4848 try :
4949 # Set temporary args for this request only
5050 server .optimizer .args .file = file_path
5151 server .optimizer .args .function = None # Always get ALL functions, not just one
5252 server .optimizer .args .previous_checkpoint_functions = False
53-
53+
5454 server .show_message_log ("Calling get_optimizable_functions..." , "Info" )
5555 optimizable_funcs , _ = server .optimizer .get_optimizable_functions ()
56-
56+
5757 path_to_qualified_names = {}
5858 for path , functions in optimizable_funcs .items ():
5959 path_to_qualified_names [path .as_posix ()] = [func .qualified_name for func in functions ]
60-
61- server .show_message_log (f"Found { len (path_to_qualified_names )} files with functions: { path_to_qualified_names } " , "Info" )
60+
61+ server .show_message_log (
62+ f"Found { len (path_to_qualified_names )} files with functions: { path_to_qualified_names } " , "Info"
63+ )
6264 return path_to_qualified_names
6365 finally :
6466 # Restore original args to prevent state corruption
@@ -70,8 +72,10 @@ def get_optimizable_functions(
7072 server .optimizer .args .function = None
7173 if original_checkpoint is not None :
7274 server .optimizer .args .previous_checkpoint_functions = original_checkpoint
73-
74- server .show_message_log (f"Restored args - file: { server .optimizer .args .file } , function: { server .optimizer .args .function } " , "Info" )
75+
76+ server .show_message_log (
77+ f"Restored args - file: { server .optimizer .args .file } , function: { server .optimizer .args .function } " , "Info"
78+ )
7579
7680
7781@server .feature ("initializeFunctionOptimization" )
@@ -80,18 +84,20 @@ def initialize_function_optimization(
8084) -> dict [str , str ]:
8185 file_path = Path (uris .to_fs_path (params .textDocument .uri ))
8286 server .show_message_log (f"Initializing optimization for function: { params .functionName } in { file_path } " , "Info" )
83-
87+
8488 # IMPORTANT: Store the specific function for optimization, but don't corrupt global state
8589 server .optimizer .args .function = params .functionName
8690 server .optimizer .args .file = file_path
87-
88- server .show_message_log (f"Args set - function: { server .optimizer .args .function } , file: { server .optimizer .args .file } " , "Info" )
89-
91+
92+ server .show_message_log (
93+ f"Args set - function: { server .optimizer .args .function } , file: { server .optimizer .args .file } " , "Info"
94+ )
95+
9096 optimizable_funcs , _ = server .optimizer .get_optimizable_functions ()
9197 if not optimizable_funcs :
9298 server .show_message_log (f"No optimizable functions found for { params .functionName } " , "Warning" )
9399 return {"functionName" : params .functionName , "status" : "not found" , "args" : None }
94-
100+
95101 fto = optimizable_funcs .popitem ()[1 ][0 ]
96102 server .optimizer .current_function_being_optimized = fto
97103 server .show_message_log (f"Successfully initialized optimization for { params .functionName } " , "Info" )
@@ -174,15 +180,19 @@ def generate_tests(server: CodeflashLanguageServer, params: FunctionOptimization
174180
175181
176182@server .feature ("performFunctionOptimization" )
177- def perform_function_optimization (
183+ def perform_function_optimization ( # noqa: PLR0911
178184 server : CodeflashLanguageServer , params : FunctionOptimizationParams
179185) -> dict [str , str ]:
180186 server .show_message_log (f"Starting optimization for function: { params .functionName } " , "Info" )
181187 current_function = server .optimizer .current_function_being_optimized
182-
188+
183189 if not current_function :
184190 server .show_message_log (f"No current function being optimized for { params .functionName } " , "Error" )
185- return {"functionName" : params .functionName , "status" : "error" , "message" : "No function currently being optimized" }
191+ return {
192+ "functionName" : params .functionName ,
193+ "status" : "error" ,
194+ "message" : "No function currently being optimized" ,
195+ }
186196
187197 module_prep_result = server .optimizer .prepare_module_for_optimization (current_function .file_path )
188198
@@ -257,7 +267,9 @@ def perform_function_optimization(
257267 )
258268
259269 if not best_optimization :
260- server .show_message_log (f"No best optimizations found for function { function_to_optimize_qualified_name } " , "Warning" )
270+ server .show_message_log (
271+ f"No best optimizations found for function { function_to_optimize_qualified_name } " , "Warning"
272+ )
261273 return {
262274 "functionName" : params .functionName ,
263275 "status" : "error" ,
@@ -266,9 +278,9 @@ def perform_function_optimization(
266278
267279 optimized_source = best_optimization .candidate .source_code
268280 speedup = original_code_baseline .runtime / best_optimization .runtime
269-
281+
270282 server .show_message_log (f"Optimization completed for { params .functionName } with { speedup :.2f} x speedup" , "Info" )
271-
283+
272284 # CRITICAL: Clear the function filter after optimization to prevent state corruption
273285 server .optimizer .args .function = None
274286 server .show_message_log ("Cleared function filter to prevent state corruption" , "Info" )
0 commit comments