Skip to content

Commit a307d81

Browse files
lsp: return to the client why the codeflash config is not valid (#806)
Co-authored-by: Sarthak Agarwal <sarthak.saga@gmail.com>
1 parent 8599750 commit a307d81

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

codeflash/cli_cmds/cmd_init.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -155,20 +155,30 @@ def ask_run_end_to_end_test(args: Namespace) -> None:
155155
run_end_to_end_test(args, bubble_sort_path, bubble_sort_test_path)
156156

157157

158-
def is_valid_pyproject_toml(pyproject_toml_path: Path) -> dict[str, Any] | None:
158+
def is_valid_pyproject_toml(pyproject_toml_path: Path) -> tuple[dict[str, Any] | None, str]: # noqa: PLR0911
159159
if not pyproject_toml_path.exists():
160-
return None
160+
return None, f"Configuration file not found: {pyproject_toml_path}"
161+
161162
try:
162163
config, _ = parse_config_file(pyproject_toml_path)
163-
except Exception:
164-
return None
164+
except Exception as e:
165+
return None, f"Failed to parse configuration: {e}"
166+
167+
module_root = config.get("module_root")
168+
if not module_root:
169+
return None, "Missing required field: 'module_root'"
170+
171+
if not Path(module_root).is_dir():
172+
return None, f"Invalid 'module_root': directory does not exist at {module_root}"
173+
174+
tests_root = config.get("tests_root")
175+
if not tests_root:
176+
return None, "Missing required field: 'tests_root'"
165177

166-
if "module_root" not in config or config["module_root"] is None or not Path(config["module_root"]).is_dir():
167-
return None
168-
if "tests_root" not in config or config["tests_root"] is None or not Path(config["tests_root"]).is_dir():
169-
return None
178+
if not Path(tests_root).is_dir():
179+
return None, f"Invalid 'tests_root': directory does not exist at {tests_root}"
170180

171-
return config
181+
return config, ""
172182

173183

174184
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]:
180190

181191
pyproject_toml_path = Path.cwd() / "pyproject.toml"
182192

183-
config = is_valid_pyproject_toml(pyproject_toml_path)
193+
config, _message = is_valid_pyproject_toml(pyproject_toml_path)
184194
if config is None:
185195
return True, None
186196

@@ -631,7 +641,7 @@ def check_for_toml_or_setup_file() -> str | None:
631641

632642
def install_github_actions(override_formatter_check: bool = False) -> None: # noqa: FBT001, FBT002
633643
try:
634-
config, config_file_path = parse_config_file(override_formatter_check=override_formatter_check)
644+
config, _config_file_path = parse_config_file(override_formatter_check=override_formatter_check)
635645

636646
ph("cli-github-actions-install-started")
637647
try:

codeflash/lsp/beta.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,10 @@ def init_project(server: CodeflashLanguageServer, params: ValidateProjectParams)
191191
}
192192

193193
server.show_message_log("Validating project...", "Info")
194-
config = is_valid_pyproject_toml(pyproject_toml_path)
194+
config, reason = is_valid_pyproject_toml(pyproject_toml_path)
195195
if config is None:
196196
server.show_message_log("pyproject.toml is not valid", "Error")
197-
return {"status": "error", "message": "not valid", "pyprojectPath": pyproject_toml_path}
197+
return {"status": "error", "message": f"reason: {reason}", "pyprojectPath": pyproject_toml_path}
198198

199199
args = process_args(server)
200200

0 commit comments

Comments
 (0)