feat: add BuildCodeGraph use case, sink orchestration out of presentation
This commit is contained in:
67
crates/application/src/use_cases/build_code_graph.rs
Normal file
67
crates/application/src/use_cases/build_code_graph.rs
Normal file
@@ -0,0 +1,67 @@
|
||||
use std::path::Path;
|
||||
|
||||
use archlens_domain::{
|
||||
AnalysisConfig, AnalysisWarning, DiagramLevel, DomainError, NormalizedGraph,
|
||||
ports::{FileDiscovery, ProjectAnalyzer, SourceAnalyzer},
|
||||
};
|
||||
|
||||
use crate::queries::AnalyzeCodebase;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct BuildCodeGraphResult {
|
||||
pub graph: NormalizedGraph,
|
||||
pub warnings: Vec<AnalysisWarning>,
|
||||
}
|
||||
|
||||
pub struct BuildCodeGraph<F, S>
|
||||
where
|
||||
F: FileDiscovery + Send + Sync,
|
||||
S: SourceAnalyzer,
|
||||
{
|
||||
pub discovery: F,
|
||||
pub source_analyzer: S,
|
||||
pub project_analyzer: Option<Box<dyn ProjectAnalyzer>>,
|
||||
}
|
||||
|
||||
impl<F, S> BuildCodeGraph<F, S>
|
||||
where
|
||||
F: FileDiscovery + Send + Sync,
|
||||
S: SourceAnalyzer,
|
||||
{
|
||||
pub fn execute(
|
||||
self,
|
||||
root: &Path,
|
||||
config: &AnalysisConfig,
|
||||
level: DiagramLevel,
|
||||
) -> Result<BuildCodeGraphResult, DomainError> {
|
||||
match level {
|
||||
DiagramLevel::Project => {
|
||||
let pa = self.project_analyzer.ok_or_else(|| {
|
||||
DomainError::AnalysisError(
|
||||
"no project analyzer available for Project level".into(),
|
||||
)
|
||||
})?;
|
||||
let cg = pa.analyze(root)?;
|
||||
Ok(BuildCodeGraphResult {
|
||||
graph: NormalizedGraph::from_project(cg),
|
||||
warnings: Vec::new(),
|
||||
})
|
||||
}
|
||||
DiagramLevel::Module | DiagramLevel::Type => {
|
||||
let analyze = AnalyzeCodebase::new(self.discovery, self.source_analyzer);
|
||||
let result = analyze.execute(root, config)?;
|
||||
let mut graph = result.graph().clone();
|
||||
if level == DiagramLevel::Module {
|
||||
if let Some(pa) = self.project_analyzer {
|
||||
let project_cg = pa.analyze(root)?;
|
||||
graph.merge_project_edges(&project_cg);
|
||||
}
|
||||
}
|
||||
Ok(BuildCodeGraphResult {
|
||||
graph,
|
||||
warnings: result.warnings().to_vec(),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
pub mod build_code_graph;
|
||||
pub mod check_freshness;
|
||||
pub mod diff_diagram;
|
||||
pub mod generate_diagram;
|
||||
|
||||
Reference in New Issue
Block a user