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