use anyhow::{Context, Result};
use colored::Colorize;
pub fn build_analysis_graph(
workspace_path: &std::path::Path,
verbose: bool,
) -> Result<unfault_analysis::graph::CodeGraph> {
use crate::session::ir_builder::build_ir_cached;
if verbose {
eprintln!(
"{} Building code graph for: {}",
"→".cyan(),
workspace_path.display()
);
}
let build_result = build_ir_cached(workspace_path, None, verbose)
.context("Failed to build IR for graph analysis")?;
let ir_json = serde_json::to_string(&build_result.ir).context("Failed to serialize IR")?;
let mut ir: unfault_analysis::ir::IntermediateRepresentation =
serde_json::from_str(&ir_json).context("Failed to deserialize IR for graph")?;
ir.rebuild_indexes();
if verbose {
eprintln!(
"{} Graph: {} files, {} functions",
"✓".green(),
ir.graph.file_nodes.len(),
ir.graph.function_nodes.len(),
);
}
Ok(ir.graph)
}