|
6 | 6 |
|
7 | 7 | from pygls import uris |
8 | 8 |
|
| 9 | +from codeflash.either import is_successful |
9 | 10 | from codeflash.lsp.server import CodeflashLanguageServer, CodeflashLanguageServerProtocol |
10 | 11 |
|
11 | 12 | if TYPE_CHECKING: |
@@ -80,30 +81,23 @@ def third_step_in_optimize_function(server: CodeflashLanguageServer, params: Opt |
80 | 81 | ) |
81 | 82 |
|
82 | 83 | server.optimizer.current_function_optimizer = function_optimizer |
| 84 | + if not function_optimizer: |
| 85 | + return {"functionName": params.functionName, "status": "error", "message": "No function optimizer found"} |
| 86 | + |
| 87 | + initialization_result = function_optimizer.can_be_optimized() |
| 88 | + if not is_successful(initialization_result): |
| 89 | + return {"functionName": params.functionName, "status": "error", "message": initialization_result.failure()} |
| 90 | + |
| 91 | + should_run_experiment, code_context, original_helper_code = initialization_result.unwrap() |
83 | 92 |
|
84 | 93 | return { |
85 | 94 | "functionName": params.functionName, |
86 | 95 | "status": "success", |
87 | | - "message": "Function optimizer created successfully", |
88 | | - "extra": function_optimizer.function_to_tests, |
| 96 | + "message": "Function can be optimized", |
| 97 | + "extra": original_helper_code, |
89 | 98 | } |
90 | 99 |
|
91 | 100 |
|
92 | | -@server.feature("fourth_step_in_optimize_function") |
93 | | -def fourth_step_in_optimize_function(server: CodeflashLanguageServer, params: OptimizeFunctionParams) -> dict[str, str]: |
94 | | - current_function_optimizer = server.optimizer.current_function_optimizer |
95 | | - |
96 | | - if not current_function_optimizer: |
97 | | - return {"functionName": params.functionName, "status": "error", "message": "No function optimizer found"} |
98 | | - |
99 | | - optimized_code = current_function_optimizer.optimize_function() |
100 | | - |
101 | | - if not optimized_code: |
102 | | - return {"functionName": params.functionName, "status": "error", "message": "Optimization failed"} |
103 | | - |
104 | | - return {"functionName": params.functionName, "status": "success", "optimized_code": optimized_code} |
105 | | - |
106 | | - |
107 | 101 | if __name__ == "__main__": |
108 | 102 | from codeflash.cli_cmds.console import console |
109 | 103 |
|
|
0 commit comments