Skip to main content

detect_project_root

Function detect_project_root 

Source
pub fn detect_project_root(file_path: &str) -> Option<String>
Expand description

Finds the project root by walking up from file_path.

Only a repository or a workspace widens the root to an outer directory: the outermost ancestor with .git wins (a monorepo with nested .git dirs, e.g. mono/backend/.git + mono/frontend/.git, is one project), else the outermost workspace marker (go.work, pnpm-workspace.yaml, …), else the innermost generic marker (Cargo.toml, package.json, Makefile, …). A stray Makefile or package.json in an ancestor (~/code/Makefile) no longer makes that ancestor the project.