Skip to main content

callisto_graph/locate/
mod.rs

1use std::path::PathBuf;
2
3use callisto_model::{DeclaredEdge, ProjectRoot};
4
5pub mod git;
6pub mod ignore_walk;
7pub mod root;
8
9pub use git::probe_git;
10pub use ignore_walk::IgnoreWalkLocator;
11pub use root::find_workspace_root;
12
13pub trait ProjectLocator: Send + Sync {
14    fn projects(&self) -> Result<Vec<ProjectRoot>, LocateError>;
15    fn declared_edges(&self) -> Option<Vec<DeclaredEdge>> {
16        None
17    }
18}
19
20#[derive(Clone, Debug, thiserror::Error, miette::Diagnostic, PartialEq, Eq)]
21#[non_exhaustive]
22pub enum LocateError {
23    #[error("workspace root not found starting from `{start}`")]
24    #[diagnostic(
25        code(E030),
26        help(
27            "No workspace root found. Ensure the directory tree contains a workspace manifest: \
28             Cargo.toml with [workspace], package.json with a workspaces field, \
29             pnpm-workspace.yaml, or a .moon directory."
30        )
31    )]
32    WorkspaceRootNotFound { start: PathBuf },
33
34    #[error("failed to walk filesystem under `{path}`: {message}")]
35    #[diagnostic(code(E031))]
36    Walk { path: PathBuf, message: String },
37
38    #[error("project path `{path}` is outside the workspace root `{root}`")]
39    #[diagnostic(code(E032))]
40    OutsideWorkspaceRoot { path: PathBuf, root: PathBuf },
41
42    #[error("moon CLI is unavailable or exited non-zero")]
43    MoonUnavailable,
44
45    #[error("Failed to parse moon project-graph output: {message}")]
46    MoonOutputParse { message: String },
47
48    #[error("Incompatible moon version found: {found}, required: {required}")]
49    IncompatibleMoonVersion { found: String, required: String },
50
51    #[error(transparent)]
52    Graph(#[from] Box<crate::error::GraphError>),
53}