From a0a7bf029c820b086806ab1ef036f54de95ce344 Mon Sep 17 00:00:00 2001 From: ali Date: Thu, 9 Oct 2025 22:37:42 +0300 Subject: [PATCH] lsp: return to the client why the codeflash config is not valid --- codeflash/cli_cmds/cmd_init.py | 32 +++++++++++++++++++++----------- codeflash/lsp/beta.py | 4 ++-- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/codeflash/cli_cmds/cmd_init.py b/codeflash/cli_cmds/cmd_init.py index 1e5b44ee6..d89af2c51 100644 --- a/codeflash/cli_cmds/cmd_init.py +++ b/codeflash/cli_cmds/cmd_init.py @@ -155,20 +155,30 @@ 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: +def is_valid_pyproject_toml(pyproject_toml_path: Path) -> tuple[dict[str, Any] | None, str]: # noqa: PLR0911 if not pyproject_toml_path.exists(): - return None + return None, f"Configuration file not found: {pyproject_toml_path}" + try: config, _ = parse_config_file(pyproject_toml_path) - except Exception: - return None + except Exception as e: + return None, f"Failed to parse configuration: {e}" + + module_root = config.get("module_root") + if not module_root: + return None, "Missing required field: 'module_root'" + + if not Path(module_root).is_dir(): + return None, f"Invalid 'module_root': directory does not exist at {module_root}" + + tests_root = config.get("tests_root") + if not tests_root: + return None, "Missing required field: 'tests_root'" - 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 + if not Path(tests_root).is_dir(): + return None, f"Invalid 'tests_root': directory does not exist at {tests_root}" - return config + return config, "" def should_modify_pyproject_toml() -> tuple[bool, dict[str, Any] | None]: @@ -180,7 +190,7 @@ def should_modify_pyproject_toml() -> tuple[bool, dict[str, Any] | None]: pyproject_toml_path = Path.cwd() / "pyproject.toml" - config = is_valid_pyproject_toml(pyproject_toml_path) + config, _message = is_valid_pyproject_toml(pyproject_toml_path) if config is None: return True, None @@ -631,7 +641,7 @@ def check_for_toml_or_setup_file() -> str | None: def install_github_actions(override_formatter_check: bool = False) -> None: # noqa: FBT001, FBT002 try: - config, config_file_path = parse_config_file(override_formatter_check=override_formatter_check) + config, _config_file_path = parse_config_file(override_formatter_check=override_formatter_check) ph("cli-github-actions-install-started") try: diff --git a/codeflash/lsp/beta.py b/codeflash/lsp/beta.py index b249025d4..c38ae4f0b 100644 --- a/codeflash/lsp/beta.py +++ b/codeflash/lsp/beta.py @@ -190,10 +190,10 @@ def init_project(server: CodeflashLanguageServer, params: ValidateProjectParams) } server.show_message_log("Validating project...", "Info") - config = is_valid_pyproject_toml(pyproject_toml_path) + config, reason = is_valid_pyproject_toml(pyproject_toml_path) if config is None: server.show_message_log("pyproject.toml is not valid", "Error") - return {"status": "error", "message": "not valid", "pyprojectPath": pyproject_toml_path} + return {"status": "error", "message": f"reason: {reason}", "pyprojectPath": pyproject_toml_path} args = process_args(server) repo = git.Repo(args.module_root, search_parent_directories=True)