|
11 | 11 | from codeflash.api.cfapi import get_codeflash_api_key, get_user_id |
12 | 12 | from codeflash.code_utils.git_utils import create_diff_patch_from_worktree |
13 | 13 | from codeflash.code_utils.shell_utils import save_api_key_to_rc |
| 14 | +from codeflash.discovery.functions_to_optimize import filter_functions, get_functions_within_git_diff |
14 | 15 | from codeflash.either import is_successful |
15 | 16 | from codeflash.lsp.server import CodeflashLanguageServer, CodeflashLanguageServerProtocol |
16 | 17 | from codeflash.result.explanation import Explanation |
@@ -40,6 +41,23 @@ class ProvideApiKeyParams: |
40 | 41 | server = CodeflashLanguageServer("codeflash-language-server", "v1.0", protocol_cls=CodeflashLanguageServerProtocol) |
41 | 42 |
|
42 | 43 |
|
| 44 | +@server.feature("getOptimizableFunctionsInCurrentDiff") |
| 45 | +def get_functions_in_current_git_diff( |
| 46 | + server: CodeflashLanguageServer, _params: OptimizableFunctionsParams |
| 47 | +) -> dict[str, str | list[str]]: |
| 48 | + functions = get_functions_within_git_diff(uncommitted_changes=True) |
| 49 | + file_to_funcs_to_optimize, _ = filter_functions( |
| 50 | + modified_functions=functions, |
| 51 | + tests_root=server.optimizer.test_cfg.tests_root, |
| 52 | + ignore_paths=[], |
| 53 | + project_root=server.optimizer.args.project_root, |
| 54 | + module_root=server.optimizer.args.module_root, |
| 55 | + previous_checkpoint_functions={}, |
| 56 | + ) |
| 57 | + qualified_names: list[str] = [func.qualified_name for funcs in file_to_funcs_to_optimize.values() for func in funcs] |
| 58 | + return {"functions": qualified_names, "status": "success"} |
| 59 | + |
| 60 | + |
43 | 61 | @server.feature("getOptimizableFunctions") |
44 | 62 | def get_optimizable_functions( |
45 | 63 | server: CodeflashLanguageServer, params: OptimizableFunctionsParams |
|
0 commit comments