From 0cd4d5efabdda495393195ab054c5235d9e6cfeb Mon Sep 17 00:00:00 2001 From: ali Date: Tue, 19 Aug 2025 22:02:23 +0300 Subject: [PATCH 1/8] validating python and git environment with the lsp --- codeflash/cli_cmds/cli.py | 4 ++ codeflash/cli_cmds/cmd_init.py | 34 +++++++++++----- codeflash/code_utils/git_utils.py | 5 ++- codeflash/discovery/functions_to_optimize.py | 4 ++ codeflash/lsp/beta.py | 43 ++++++++++++++++++-- codeflash/lsp/server.py | 3 +- 6 files changed, 75 insertions(+), 18 deletions(-) diff --git a/codeflash/cli_cmds/cli.py b/codeflash/cli_cmds/cli.py index 5aa331f36..3f8f8767a 100644 --- a/codeflash/cli_cmds/cli.py +++ b/codeflash/cli_cmds/cli.py @@ -10,6 +10,7 @@ from codeflash.code_utils import env_utils from codeflash.code_utils.code_utils import exit_with_message from codeflash.code_utils.config_parser import parse_config_file +from codeflash.lsp.helpers import is_LSP_enabled from codeflash.version import __version__ as version @@ -211,6 +212,9 @@ def process_pyproject_config(args: Namespace) -> Namespace: if args.benchmarks_root: args.benchmarks_root = Path(args.benchmarks_root).resolve() args.test_project_root = project_root_from_module_root(args.tests_root, pyproject_file_path) + if is_LSP_enabled(): + args.all = None + return args return handle_optimize_all_arg_parsing(args) diff --git a/codeflash/cli_cmds/cmd_init.py b/codeflash/cli_cmds/cmd_init.py index 57133fa16..3c9a4d65d 100644 --- a/codeflash/cli_cmds/cmd_init.py +++ b/codeflash/cli_cmds/cmd_init.py @@ -155,6 +155,22 @@ def ask_run_end_to_end_test(args: Namespace) -> None: run_end_to_end_test(args, bubble_sort_path, bubble_sort_test_path) +def is_valid_pyproject_toml(pyproject_toml_path: Path) -> dict[str, Any] | None: + if not pyproject_toml_path.exists(): + return None + try: + config, _ = parse_config_file(pyproject_toml_path) + except Exception: + return None + + if "module_root" not in config or config["module_root"] is None or not Path(config["module_root"]).is_dir(): + return None + if "tests_root" not in config or config["tests_root"] is None or not Path(config["tests_root"]).is_dir(): + return None + + return config + + def should_modify_pyproject_toml() -> tuple[bool, dict[str, Any] | None]: """Check if the current directory contains a valid pyproject.toml file with codeflash config. @@ -163,16 +179,9 @@ def should_modify_pyproject_toml() -> tuple[bool, dict[str, Any] | None]: from rich.prompt import Confirm pyproject_toml_path = Path.cwd() / "pyproject.toml" - if not pyproject_toml_path.exists(): - return True, None - try: - config, config_file_path = parse_config_file(pyproject_toml_path) - except Exception: - return True, None - if "module_root" not in config or config["module_root"] is None or not Path(config["module_root"]).is_dir(): - return True, None - if "tests_root" not in config or config["tests_root"] is None or not Path(config["tests_root"]).is_dir(): + config = is_valid_pyproject_toml(pyproject_toml_path) + if config is None: return True, None return Confirm.ask( @@ -442,7 +451,7 @@ def collect_setup_info() -> SetupInfo: apologize_and_exit() formatter = formatter_answers["formatter"] - git_remote = "" + git_remote = "origin" try: repo = Repo(str(module_root), search_parent_directories=True) git_remotes = get_git_remotes(repo) @@ -968,6 +977,11 @@ def install_github_app(git_remote: str) -> None: except git.InvalidGitRepositoryError: click.echo("Skipping GitHub app installation because you're not in a git repository.") return + + if git_remote not in get_git_remotes(git_repo): + click.echo(f"Skipping GitHub app installation, remote ({git_remote}) does not exist in this repository.") + return + owner, repo = get_repo_owner_and_name(git_repo, git_remote) if is_github_app_installed_on_repo(owner, repo, suppress_errors=True): diff --git a/codeflash/code_utils/git_utils.py b/codeflash/code_utils/git_utils.py index b4f658097..70ed47e8b 100644 --- a/codeflash/code_utils/git_utils.py +++ b/codeflash/code_utils/git_utils.py @@ -201,7 +201,8 @@ def get_last_commit_author_if_pr_exists(repo: Repo | None = None) -> str | None: def create_worktree_snapshot_commit(worktree_dir: Path, commit_message: str) -> None: repository = git.Repo(worktree_dir, search_parent_directories=True) - repository.git.commit("-am", commit_message, "--no-verify") + repository.git.add(".") + repository.git.commit("-m", commit_message, "--no-verify") def create_detached_worktree(module_root: Path) -> Optional[Path]: @@ -234,7 +235,7 @@ def create_detached_worktree(module_root: Path) -> Optional[Path]: # Apply the patch inside the worktree try: subprocess.run( - ["git", "apply", "--ignore-space-change", "--ignore-whitespace", patch_path], + ["git", "apply", "--ignore-space-change", "--ignore-whitespace", "--whitespace=nowarn", patch_path], cwd=worktree_dir, check=True, ) diff --git a/codeflash/discovery/functions_to_optimize.py b/codeflash/discovery/functions_to_optimize.py index db5d5e5d5..f284fe9d0 100644 --- a/codeflash/discovery/functions_to_optimize.py +++ b/codeflash/discovery/functions_to_optimize.py @@ -27,6 +27,7 @@ from codeflash.code_utils.git_utils import get_git_diff, get_repo_owner_and_name from codeflash.code_utils.time_utils import humanize_runtime from codeflash.discovery.discover_unit_tests import discover_unit_tests +from codeflash.lsp.helpers import is_LSP_enabled from codeflash.models.models import FunctionParent from codeflash.telemetry.posthog_cf import ph @@ -470,6 +471,9 @@ def was_function_previously_optimized( Tuple of (filtered_functions_dict, remaining_count) """ + if is_LSP_enabled: + return False + # Check optimization status if repository info is provided # already_optimized_count = 0 try: diff --git a/codeflash/lsp/beta.py b/codeflash/lsp/beta.py index f83be319f..4ea0fe9b5 100644 --- a/codeflash/lsp/beta.py +++ b/codeflash/lsp/beta.py @@ -6,6 +6,7 @@ from pathlib import Path from typing import TYPE_CHECKING +import git from pygls import uris from codeflash.api.cfapi import get_codeflash_api_key, get_user_id @@ -88,9 +89,14 @@ def initialize_function_optimization( ) -> dict[str, str]: file_path = Path(uris.to_fs_path(params.textDocument.uri)) server.show_message_log(f"Initializing optimization for function: {params.functionName} in {file_path}", "Info") + if server.optimizer is None: - _initialize_optimizer_if_valid(server) + _initialize_optimizer_if_api_key_is_valid(server) + server.optimizer.worktree_mode() + # make sure the tests dir is created in the worktree, this can happen if the original tests dir is empty + Path(server.optimizer.args.tests_root).mkdir(parents=True, exist_ok=True) + original_args, _ = server.optimizer.original_args_and_test_cfg server.optimizer.args.function = params.functionName @@ -132,7 +138,36 @@ def discover_function_tests(server: CodeflashLanguageServer, params: FunctionOpt return {"functionName": params.functionName, "status": "success", "discovered_tests": num_discovered_tests} -def _initialize_optimizer_if_valid(server: CodeflashLanguageServer) -> dict[str, str]: +@server.feature("validateProject") +def validate_project(server: CodeflashLanguageServer, _params: FunctionOptimizationParams) -> dict[str, str]: + from codeflash.cli_cmds.cli import process_pyproject_config + from codeflash.cli_cmds.cmd_init import is_valid_pyproject_toml + + server.show_message_log("Validating project...", "Info") + config = is_valid_pyproject_toml(server.args.config_file) + if config is None: + server.show_message_log("pyproject.toml is not valid", "Error") + return { + "status": "error", + "message": "pyproject.toml is not valid", + } # keep the error message the same, the extension is matching "pyproject.toml" in the error message to show the codeflash init instructions + + new_args = process_pyproject_config(server.args) + server.args = new_args + + repo = git.Repo(new_args.module_root, search_parent_directories=True) + if repo.bare: + return {"status": "error", "message": "Repository is in bare state"} + + try: + _ = repo.head.commit + except Exception: + return {"status": "error", "message": "Repository has no commits (unborn HEAD)"} + + return {"status": "success"} + + +def _initialize_optimizer_if_api_key_is_valid(server: CodeflashLanguageServer) -> dict[str, str]: user_id = get_user_id() if user_id is None: return {"status": "error", "message": "api key not found or invalid"} @@ -150,7 +185,7 @@ def _initialize_optimizer_if_valid(server: CodeflashLanguageServer) -> dict[str, @server.feature("apiKeyExistsAndValid") def check_api_key(server: CodeflashLanguageServer, _params: any) -> dict[str, str]: try: - return _initialize_optimizer_if_valid(server) + return _initialize_optimizer_if_api_key_is_valid(server) except Exception: return {"status": "error", "message": "something went wrong while validating the api key"} @@ -170,7 +205,7 @@ def provide_api_key(server: CodeflashLanguageServer, params: ProvideApiKeyParams get_codeflash_api_key.cache_clear() get_user_id.cache_clear() - init_result = _initialize_optimizer_if_valid(server) + init_result = _initialize_optimizer_if_api_key_is_valid(server) if init_result["status"] == "error": return {"status": "error", "message": "Api key is not valid"} diff --git a/codeflash/lsp/server.py b/codeflash/lsp/server.py index 8114c94dc..6aa16a6e1 100644 --- a/codeflash/lsp/server.py +++ b/codeflash/lsp/server.py @@ -49,13 +49,12 @@ def __init__(self, *args: Any, **kwargs: Any) -> None: # noqa: ANN401 self.args = None def prepare_optimizer_arguments(self, config_file: Path) -> None: - from codeflash.cli_cmds.cli import parse_args, process_pyproject_config + from codeflash.cli_cmds.cli import parse_args args = parse_args() args.config_file = config_file args.no_pr = True # LSP server should not create PRs args.worktree = True - args = process_pyproject_config(args) self.args = args # avoid initializing the optimizer during initialization, because it can cause an error if the api key is invalid From 27745fb1be8a2b94ae94a907583c3a232b9abeca Mon Sep 17 00:00:00 2001 From: ali Date: Tue, 19 Aug 2025 22:38:37 +0300 Subject: [PATCH 2/8] revert --- codeflash/cli_cmds/cmd_init.py | 2 +- codeflash/lsp/beta.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/codeflash/cli_cmds/cmd_init.py b/codeflash/cli_cmds/cmd_init.py index 3c9a4d65d..61a949d04 100644 --- a/codeflash/cli_cmds/cmd_init.py +++ b/codeflash/cli_cmds/cmd_init.py @@ -451,7 +451,7 @@ def collect_setup_info() -> SetupInfo: apologize_and_exit() formatter = formatter_answers["formatter"] - git_remote = "origin" + git_remote = "" try: repo = Repo(str(module_root), search_parent_directories=True) git_remotes = get_git_remotes(repo) diff --git a/codeflash/lsp/beta.py b/codeflash/lsp/beta.py index 4ea0fe9b5..97ebdc30e 100644 --- a/codeflash/lsp/beta.py +++ b/codeflash/lsp/beta.py @@ -149,8 +149,8 @@ def validate_project(server: CodeflashLanguageServer, _params: FunctionOptimizat server.show_message_log("pyproject.toml is not valid", "Error") return { "status": "error", - "message": "pyproject.toml is not valid", - } # keep the error message the same, the extension is matching "pyproject.toml" in the error message to show the codeflash init instructions + "message": "pyproject.toml is not valid", # keep the error message the same, the extension is matching "pyproject.toml" in the error message to show the codeflash init instructions + } new_args = process_pyproject_config(server.args) server.args = new_args From d7d17224fc3acb20fe855666484e598aeba021eb Mon Sep 17 00:00:00 2001 From: ali Date: Wed, 20 Aug 2025 11:05:38 +0300 Subject: [PATCH 3/8] fix: processing args in lsp --- codeflash/lsp/beta.py | 13 +++++++++---- codeflash/lsp/server.py | 1 + 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/codeflash/lsp/beta.py b/codeflash/lsp/beta.py index 97ebdc30e..5bd22cfa2 100644 --- a/codeflash/lsp/beta.py +++ b/codeflash/lsp/beta.py @@ -10,6 +10,7 @@ from pygls import uris from codeflash.api.cfapi import get_codeflash_api_key, get_user_id +from codeflash.cli_cmds.cli import process_pyproject_config from codeflash.code_utils.git_utils import create_diff_patch_from_worktree from codeflash.code_utils.shell_utils import save_api_key_to_rc from codeflash.discovery.functions_to_optimize import filter_functions, get_functions_within_git_diff @@ -140,7 +141,6 @@ def discover_function_tests(server: CodeflashLanguageServer, params: FunctionOpt @server.feature("validateProject") def validate_project(server: CodeflashLanguageServer, _params: FunctionOptimizationParams) -> dict[str, str]: - from codeflash.cli_cmds.cli import process_pyproject_config from codeflash.cli_cmds.cmd_init import is_valid_pyproject_toml server.show_message_log("Validating project...", "Info") @@ -152,8 +152,11 @@ def validate_project(server: CodeflashLanguageServer, _params: FunctionOptimizat "message": "pyproject.toml is not valid", # keep the error message the same, the extension is matching "pyproject.toml" in the error message to show the codeflash init instructions } - new_args = process_pyproject_config(server.args) - server.args = new_args + new_args = server.args + if not server.args_processed_before: + new_args = process_pyproject_config(server.args) + server.args = new_args + server.args_processed_before = True repo = git.Repo(new_args.module_root, search_parent_directories=True) if repo.bare: @@ -178,7 +181,9 @@ def _initialize_optimizer_if_api_key_is_valid(server: CodeflashLanguageServer) - from codeflash.optimization.optimizer import Optimizer - server.optimizer = Optimizer(server.args) + new_args = server.args if server.args_processed_before else process_pyproject_config(server.args) + server.args_processed_before = True + server.optimizer = Optimizer(new_args) return {"status": "success", "user_id": user_id} diff --git a/codeflash/lsp/server.py b/codeflash/lsp/server.py index 6aa16a6e1..37e24ab6a 100644 --- a/codeflash/lsp/server.py +++ b/codeflash/lsp/server.py @@ -46,6 +46,7 @@ class CodeflashLanguageServer(LanguageServer): def __init__(self, *args: Any, **kwargs: Any) -> None: # noqa: ANN401 super().__init__(*args, **kwargs) self.optimizer: Optimizer | None = None + self.args_processed_before: bool = False self.args = None def prepare_optimizer_arguments(self, config_file: Path) -> None: From 53660de8037940fbb8ef81d5dea8a7490bb73061 Mon Sep 17 00:00:00 2001 From: ali Date: Wed, 20 Aug 2025 11:30:42 +0300 Subject: [PATCH 4/8] typo --- codeflash/discovery/functions_to_optimize.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codeflash/discovery/functions_to_optimize.py b/codeflash/discovery/functions_to_optimize.py index f284fe9d0..f6f38ec8f 100644 --- a/codeflash/discovery/functions_to_optimize.py +++ b/codeflash/discovery/functions_to_optimize.py @@ -471,7 +471,7 @@ def was_function_previously_optimized( Tuple of (filtered_functions_dict, remaining_count) """ - if is_LSP_enabled: + if is_LSP_enabled(): return False # Check optimization status if repository info is provided From 4ad1e99351781b9be26e2cdd515f6f8376d4c7fb Mon Sep 17 00:00:00 2001 From: ali Date: Wed, 20 Aug 2025 16:50:54 +0300 Subject: [PATCH 5/8] lsp: handle when the optimized function is not found --- codeflash/code_utils/git_utils.py | 9 +++++++++ codeflash/discovery/functions_to_optimize.py | 5 +++++ codeflash/lsp/beta.py | 13 +++++-------- codeflash/version.py | 2 +- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/codeflash/code_utils/git_utils.py b/codeflash/code_utils/git_utils.py index 70ed47e8b..5583b4507 100644 --- a/codeflash/code_utils/git_utils.py +++ b/codeflash/code_utils/git_utils.py @@ -1,6 +1,7 @@ from __future__ import annotations import os +import re import shutil import subprocess import sys @@ -221,6 +222,14 @@ def create_detached_worktree(module_root: Path) -> Optional[Path]: repository.git.add("-N", ".") # add the index for untracked files to be included in the diff uni_diff_text = repository.git.diff(None, "HEAD", ignore_blank_lines=True, ignore_space_at_eol=True) + # HACK: remove binary files from the diff, find a better way # noqa: FIX004 + uni_diff_text = re.sub( + r"^diff --git a\/.*?\.(?:pyc|class|jar|exe|dll|so|dylib|o|obj|bin|pdf|jpg|jpeg|png|gif|zip|tar|gz) b\/.*?\.\w+.*?\n(?:.*?\n)*?(?=diff --git|\Z)", + "", + uni_diff_text, + flags=re.MULTILINE, + ) + if not uni_diff_text.strip(): logger.info("No uncommitted changes to copy to worktree.") return worktree_dir diff --git a/codeflash/discovery/functions_to_optimize.py b/codeflash/discovery/functions_to_optimize.py index f6f38ec8f..418fe22f6 100644 --- a/codeflash/discovery/functions_to_optimize.py +++ b/codeflash/discovery/functions_to_optimize.py @@ -169,6 +169,7 @@ def get_functions_to_optimize( ) functions: dict[str, list[FunctionToOptimize]] trace_file_path: Path | None = None + is_lsp = is_LSP_enabled() with warnings.catch_warnings(): warnings.simplefilter(action="ignore", category=SyntaxWarning) if optimize_all: @@ -186,6 +187,8 @@ def get_functions_to_optimize( if only_get_this_function is not None: split_function = only_get_this_function.split(".") if len(split_function) > 2: + if is_lsp: + return functions, 0, None exit_with_message( "Function name should be in the format 'function_name' or 'class_name.function_name'" ) @@ -201,6 +204,8 @@ def get_functions_to_optimize( ): found_function = fn if found_function is None: + if is_lsp: + return functions, 0, None exit_with_message( f"Function {only_function_name} not found in file {file}\nor the function does not have a 'return' statement or is a property" ) diff --git a/codeflash/lsp/beta.py b/codeflash/lsp/beta.py index 47c9efc8b..0be65d3d3 100644 --- a/codeflash/lsp/beta.py +++ b/codeflash/lsp/beta.py @@ -106,15 +106,12 @@ def initialize_function_optimization( f"Args set - function: {server.optimizer.args.function}, file: {server.optimizer.args.file}", "Info" ) - optimizable_funcs, _, _ = server.optimizer.get_optimizable_functions() - if not optimizable_funcs: + optimizable_funcs, count, _ = server.optimizer.get_optimizable_functions() + + if count == 0: server.show_message_log(f"No optimizable functions found for {params.functionName}", "Warning") - return { - "functionName": params.functionName, - "status": "error", - "message": "function is no found or not optimizable", - "args": None, - } + cleanup_the_optimizer(server) + return {"functionName": params.functionName, "status": "error", "message": "not found", "args": None} fto = optimizable_funcs.popitem()[1][0] server.optimizer.current_function_being_optimized = fto diff --git a/codeflash/version.py b/codeflash/version.py index 741acda63..1cd779a8d 100644 --- a/codeflash/version.py +++ b/codeflash/version.py @@ -1,2 +1,2 @@ # These version placeholders will be replaced by uv-dynamic-versioning during build. -__version__ = "0.16.5" +__version__ = "0.16.3.post94.dev0+7d3de7c5" From 0dcfc15babdd931f08032fecbea7851d1ea057ef Mon Sep 17 00:00:00 2001 From: ali Date: Wed, 20 Aug 2025 16:55:46 +0300 Subject: [PATCH 6/8] refactoring --- codeflash/lsp/beta.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/codeflash/lsp/beta.py b/codeflash/lsp/beta.py index 0be65d3d3..301ca4e44 100644 --- a/codeflash/lsp/beta.py +++ b/codeflash/lsp/beta.py @@ -18,6 +18,8 @@ from codeflash.lsp.server import CodeflashLanguageServer, CodeflashLanguageServerProtocol if TYPE_CHECKING: + from argparse import Namespace + from lsprotocol import types @@ -146,13 +148,8 @@ def validate_project(server: CodeflashLanguageServer, _params: FunctionOptimizat "message": "pyproject.toml is not valid", # keep the error message the same, the extension is matching "pyproject.toml" in the error message to show the codeflash init instructions } - new_args = server.args - if not server.args_processed_before: - new_args = process_pyproject_config(server.args) - server.args = new_args - server.args_processed_before = True - - repo = git.Repo(new_args.module_root, search_parent_directories=True) + args = process_args(server) + repo = git.Repo(args.module_root, search_parent_directories=True) if repo.bare: return {"status": "error", "message": "Repository is in bare state"} @@ -175,12 +172,20 @@ def _initialize_optimizer_if_api_key_is_valid(server: CodeflashLanguageServer) - from codeflash.optimization.optimizer import Optimizer - new_args = server.args if server.args_processed_before else process_pyproject_config(server.args) - server.args_processed_before = True + new_args = process_args(server) server.optimizer = Optimizer(new_args) return {"status": "success", "user_id": user_id} +def process_args(server: CodeflashLanguageServer) -> Namespace: + if server.args_processed_before: + return server.args + new_args = process_pyproject_config(server.args) + server.args = new_args + server.args_processed_before = True + return new_args + + @server.feature("apiKeyExistsAndValid") def check_api_key(server: CodeflashLanguageServer, _params: any) -> dict[str, str]: try: From 47a51008c83a2a4d00465c9b4b9ef2608bcb55b1 Mon Sep 17 00:00:00 2001 From: ali Date: Thu, 21 Aug 2025 14:12:28 +0300 Subject: [PATCH 7/8] native exclude for binary files in the temp diff --- codeflash/code_utils/git_utils.py | 12 +++--------- codeflash/lsp/beta.py | 2 -- codeflash/optimization/optimizer.py | 2 ++ 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/codeflash/code_utils/git_utils.py b/codeflash/code_utils/git_utils.py index 5583b4507..92f2be8a1 100644 --- a/codeflash/code_utils/git_utils.py +++ b/codeflash/code_utils/git_utils.py @@ -1,7 +1,6 @@ from __future__ import annotations import os -import re import shutil import subprocess import sys @@ -220,14 +219,9 @@ def create_detached_worktree(module_root: Path) -> Optional[Path]: # Get uncommitted diff from the original repo repository.git.add("-N", ".") # add the index for untracked files to be included in the diff - uni_diff_text = repository.git.diff(None, "HEAD", ignore_blank_lines=True, ignore_space_at_eol=True) - - # HACK: remove binary files from the diff, find a better way # noqa: FIX004 - uni_diff_text = re.sub( - r"^diff --git a\/.*?\.(?:pyc|class|jar|exe|dll|so|dylib|o|obj|bin|pdf|jpg|jpeg|png|gif|zip|tar|gz) b\/.*?\.\w+.*?\n(?:.*?\n)*?(?=diff --git|\Z)", - "", - uni_diff_text, - flags=re.MULTILINE, + exclude_binary_files = [":!*.pyc", ":!*.pyo", ":!*.pyd", ":!*.so", ":!*.dll", ":!*.whl", ":!*.egg", ":!*.egg-info", ":!*.pyz", ":!*.pkl", ":!*.pickle", ":!*.joblib", ":!*.npy", ":!*.npz", ":!*.h5", ":!*.hdf5", ":!*.pth", ":!*.pt", ":!*.pb", ":!*.onnx", ":!*.db", ":!*.sqlite", ":!*.sqlite3", ":!*.feather", ":!*.parquet", ":!*.jpg", ":!*.jpeg", ":!*.png", ":!*.gif", ":!*.bmp", ":!*.tiff", ":!*.webp", ":!*.wav", ":!*.mp3", ":!*.ogg", ":!*.flac", ":!*.mp4", ":!*.avi", ":!*.mov", ":!*.mkv", ":!*.pdf", ":!*.doc", ":!*.docx", ":!*.xls", ":!*.xlsx", ":!*.ppt", ":!*.pptx", ":!*.zip", ":!*.rar", ":!*.tar", ":!*.tar.gz", ":!*.tgz", ":!*.bz2", ":!*.xz"] # fmt: off + uni_diff_text = repository.git.diff( + None, "HEAD", "--", *exclude_binary_files, ignore_blank_lines=True, ignore_space_at_eol=True ) if not uni_diff_text.strip(): diff --git a/codeflash/lsp/beta.py b/codeflash/lsp/beta.py index 301ca4e44..3e77353f9 100644 --- a/codeflash/lsp/beta.py +++ b/codeflash/lsp/beta.py @@ -94,8 +94,6 @@ def initialize_function_optimization( _initialize_optimizer_if_api_key_is_valid(server) server.optimizer.worktree_mode() - # make sure the tests dir is created in the worktree, this can happen if the original tests dir is empty - Path(server.optimizer.args.tests_root).mkdir(parents=True, exist_ok=True) original_args, _ = server.optimizer.original_args_and_test_cfg diff --git a/codeflash/optimization/optimizer.py b/codeflash/optimization/optimizer.py index ce857f201..941705cfd 100644 --- a/codeflash/optimization/optimizer.py +++ b/codeflash/optimization/optimizer.py @@ -440,6 +440,8 @@ def worktree_mode(self) -> None: return self.current_worktree = worktree_dir self.mutate_args_for_worktree_mode(worktree_dir) + # make sure the tests dir is created in the worktree, this can happen if the original tests dir is empty + Path(self.args.tests_root).mkdir(parents=True, exist_ok=True) def mutate_args_for_worktree_mode(self, worktree_dir: Path) -> None: saved_args = copy.deepcopy(self.args) From a0e2edb5ca68bbbb88c106b447f798f5ca9ba838 Mon Sep 17 00:00:00 2001 From: ali Date: Thu, 21 Aug 2025 15:33:27 +0300 Subject: [PATCH 8/8] comment --- codeflash/discovery/functions_to_optimize.py | 1 + 1 file changed, 1 insertion(+) diff --git a/codeflash/discovery/functions_to_optimize.py b/codeflash/discovery/functions_to_optimize.py index 418fe22f6..27a46af0a 100644 --- a/codeflash/discovery/functions_to_optimize.py +++ b/codeflash/discovery/functions_to_optimize.py @@ -477,6 +477,7 @@ def was_function_previously_optimized( """ if is_LSP_enabled(): + # was_function_previously_optimized is for the checking the optimization duplicates in the github action, no need to do this in the LSP mode return False # Check optimization status if repository info is provided