Skip to content

Commit 50cba9e

Browse files
committed
restore optimizeFunction
1 parent 195e589 commit 50cba9e

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

codeflash/discovery/functions_to_optimize.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,15 @@ def qualified_name(self) -> str:
146146
def qualified_name_with_modules_from_root(self, project_root_path: Path) -> str:
147147
return f"{module_name_from_file_path(self.file_path, project_root_path)}.{self.qualified_name}"
148148

149+
@property
150+
def server_info(self) -> dict[str, str | int]:
151+
return {
152+
"file_path": str(self.file_path),
153+
"function_name": self.function_name,
154+
"starting_line": self.starting_line,
155+
"ending_line": self.ending_line,
156+
}
157+
149158

150159
def get_functions_to_optimize(
151160
optimize_all: str | None,

codeflash/lsp/beta.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,29 @@ def get_optimizable_functions(
4040
return path_to_qualified_names
4141

4242

43+
@server.feature("optimizeFunction")
44+
def optimize_function(server: CodeflashLanguageServer, params: OptimizeFunctionParams) -> dict[str, str]:
45+
file_path = Path(uris.to_fs_path(params.textDocument.uri))
46+
server.optimizer.args.function = params.functionName
47+
server.optimizer.args.file = file_path
48+
optimizable_funcs, _ = server.optimizer.get_optimizable_functions()
49+
if not optimizable_funcs:
50+
return {"functionName": params.functionName, "status": "not found", "args": None}
51+
fto = optimizable_funcs.popitem()[1][0]
52+
server.optimizer.current_function_being_optimized = fto
53+
return {"functionName": params.functionName, "status": "success", "info": fto.server_info}
54+
55+
56+
@server.feature("second_step_in_optimize_function")
57+
def second_step_in_optimize_function(server: CodeflashLanguageServer, params: OptimizeFunctionParams) -> dict[str, str]: # noqa: ARG001
58+
return {
59+
"functionName": params.functionName,
60+
"status": "success",
61+
"generated_tests": "5",
62+
"generated_optimizations": "3",
63+
}
64+
65+
4366
if __name__ == "__main__":
4467
from codeflash.cli_cmds.console import console
4568

0 commit comments

Comments
 (0)