Skip to content

Commit 8599750

Browse files
lsp: always process the server args when calling initProject (#804)
Co-authored-by: Sarthak Agarwal <sarthak.saga@gmail.com>
1 parent 925075a commit 8599750

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

codeflash/lsp/beta.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from pathlib import Path
77
from typing import TYPE_CHECKING, Optional
88

9-
import git
109
from pygls import uris
1110

1211
from codeflash.api.cfapi import get_codeflash_api_key, get_user_id
@@ -155,11 +154,13 @@ def _find_pyproject_toml(workspace_path: str) -> tuple[Path | None, bool]:
155154

156155
# should be called the first thing to initialize and validate the project
157156
@server.feature("initProject")
158-
def init_project(server: CodeflashLanguageServer, params: ValidateProjectParams) -> dict[str, str]: # noqa: PLR0911
157+
def init_project(server: CodeflashLanguageServer, params: ValidateProjectParams) -> dict[str, str]:
159158
from codeflash.cli_cmds.cmd_init import is_valid_pyproject_toml
160159

161-
pyproject_toml_path: Path | None = getattr(params, "config_file", None) or getattr(server.args, "config_file", None)
160+
# Always process args in the init project, the extension can call
161+
server.args_processed_before = False
162162

163+
pyproject_toml_path: Path | None = getattr(params, "config_file", None) or getattr(server.args, "config_file", None)
163164
if pyproject_toml_path is not None:
164165
# if there is a config file provided use it
165166
server.prepare_optimizer_arguments(pyproject_toml_path)
@@ -196,14 +197,6 @@ def init_project(server: CodeflashLanguageServer, params: ValidateProjectParams)
196197
return {"status": "error", "message": "not valid", "pyprojectPath": pyproject_toml_path}
197198

198199
args = process_args(server)
199-
repo = git.Repo(args.module_root, search_parent_directories=True)
200-
if repo.bare:
201-
return {"status": "error", "message": "Repository is in bare state"}
202-
203-
try:
204-
_ = repo.head.commit
205-
except Exception:
206-
return {"status": "error", "message": "Repository has no commits (unborn HEAD)"}
207200

208201
return {"status": "success", "moduleRoot": args.module_root, "pyprojectPath": pyproject_toml_path, "root": root}
209202

0 commit comments

Comments
 (0)