Skip to main content

meta_ast/
pipeline.rs

1use std::path::Path;
2use std::sync::Arc;
3
4use crate::error::Diagnostic;
5use crate::graph::{CodeGraph, GraphBuilder, SccAnalysis};
6use crate::input;
7use crate::model::SnapshotId;
8
9/// Metadata about a snapshot analysis run.
10#[derive(Debug, Clone)]
11pub struct SnapshotMeta {
12    pub id: SnapshotId,
13    pub datagraph_schema_version: u32,
14}
15
16/// Result of the full graph analysis pipeline.
17pub struct GraphAnalysis {
18    pub graph: CodeGraph,
19    pub scc: SccAnalysis,
20    pub snapshot_id: SnapshotId,
21    pub extractions: Vec<Arc<crate::model::FileExtraction>>,
22}
23
24/// Run the full graph analysis pipeline on a path.
25///
26/// Discovers files, extracts symbols/imports/references in parallel,
27/// builds the dependency graph, resolves cross-file references,
28/// and computes SCC analysis.
29pub fn analyze_graph(
30    root: &Path,
31    snapshot_id: SnapshotId,
32) -> anyhow::Result<(GraphAnalysis, Vec<Diagnostic>)> {
33    let files = input::discover_files(root, None)?;
34    let extraction = crate::extractor::extract(&files);
35    let mut diagnostics: Vec<Diagnostic> = extraction
36        .files
37        .iter()
38        .flat_map(|f| f.diagnostics.iter().cloned())
39        .collect();
40
41    let arc_extractions: Vec<_> = extraction.files.into_iter().map(Arc::new).collect();
42
43    let (graph, scc) =
44        GraphBuilder::from_extractions(&arc_extractions, root, snapshot_id, &mut diagnostics);
45
46    Ok((
47        GraphAnalysis {
48            graph,
49            scc,
50            snapshot_id,
51            extractions: arc_extractions,
52        },
53        diagnostics,
54    ))
55}
56
57/// Build a SnapshotMeta for the current analysis run.
58pub fn snapshot_meta(snapshot_id: SnapshotId) -> SnapshotMeta {
59    SnapshotMeta {
60        id: snapshot_id,
61        datagraph_schema_version: crate::output::graph::SCHEMA_VERSION,
62    }
63}