use anyhow::{Context, Result};
use colored::Colorize;
pub fn build_analysis_graph_with_semantics(
workspace_path: &std::path::Path,
verbose: bool,
) -> Result<(
unfault_analysis::graph::CodeGraph,
Vec<unfault_core::semantics::SourceSemantics>,
)> {
use crate::session::ir_builder::build_ir_cached;
let build_result = build_ir_cached(workspace_path, None, verbose)
.context("Failed to build IR for graph analysis")?;
let semantics = build_result.ir.semantics;
let graph = unfault_analysis::graph::CodeGraph::from(build_result.ir.graph);
Ok((graph, semantics))
}
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, try_load_code_graph_only};
if verbose {
eprintln!(
"{} Building code graph for: {}",
"→".cyan(),
workspace_path.display()
);
}
if let Some(graph) =
try_load_code_graph_only(workspace_path, verbose).context("Failed to check graph cache")?
{
let graph = unfault_analysis::graph::CodeGraph::from(graph);
if verbose {
eprintln!(
"{} Graph: {} files, {} functions",
"✓".green(),
graph.file_nodes.len(),
graph.function_nodes.len()
);
}
return Ok(graph);
}
let build_result = build_ir_cached(workspace_path, None, verbose)
.context("Failed to build IR for graph analysis")?;
let graph = unfault_analysis::graph::CodeGraph::from(build_result.ir.graph);
if verbose {
eprintln!(
"{} Graph: {} files, {} functions",
"✓".green(),
graph.file_nodes.len(),
graph.function_nodes.len(),
);
}
Ok(graph)
}