Skip to main content

meta_ast/
pipeline.rs

1use std::path::Path;
2
3use crate::error::Diagnostic;
4use crate::graph::{CodeGraph, GraphBuilder, SccAnalysis};
5use crate::input;
6use crate::model::SnapshotId;
7
8/// Result of the full graph analysis pipeline.
9pub struct GraphAnalysis {
10    pub graph: CodeGraph,
11    pub scc: SccAnalysis,
12    pub snapshot_id: SnapshotId,
13}
14
15/// Run the full graph analysis pipeline on a path.
16///
17/// Discovers files, extracts symbols/imports/references in parallel,
18/// builds the dependency graph, resolves cross-file references,
19/// and computes SCC analysis.
20pub fn analyze_graph(
21    root: &Path,
22    snapshot_id: SnapshotId,
23) -> anyhow::Result<(GraphAnalysis, Vec<Diagnostic>)> {
24    let files = input::discover_files(root, None)?;
25    let extraction = crate::extractor::extract(&files);
26    let mut diagnostics: Vec<Diagnostic> = extraction
27        .files
28        .iter()
29        .flat_map(|f| f.diagnostics.iter().cloned())
30        .collect();
31
32    let (graph, scc) =
33        GraphBuilder::from_extractions(&extraction.files, root, snapshot_id, &mut diagnostics);
34
35    Ok((
36        GraphAnalysis {
37            graph,
38            scc,
39            snapshot_id,
40        },
41        diagnostics,
42    ))
43}