refactor: extract module_edges() to CodeGraph domain — removes duplication from Mermaid and D2 renderers
This commit is contained in:
@@ -92,49 +92,14 @@ fn render_type(graph: &CodeGraph) -> String {
|
||||
}
|
||||
|
||||
fn render_module(graph: &CodeGraph) -> String {
|
||||
use archlens_domain::RelationshipKind;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
let mut lines = Vec::new();
|
||||
let mut modules: HashSet<String> = HashSet::new();
|
||||
let mut name_to_module: HashMap<&str, &str> = HashMap::new();
|
||||
|
||||
for el in graph.elements() {
|
||||
if let Some(m) = el.module() {
|
||||
modules.insert(m.as_str().to_string());
|
||||
name_to_module.insert(el.qualified_name(), m.as_str());
|
||||
name_to_module.insert(el.name(), m.as_str());
|
||||
}
|
||||
for module in graph.modules() {
|
||||
let id = sanitize(module.as_str());
|
||||
lines.push(format!("{id}: {}", module.as_str()));
|
||||
}
|
||||
|
||||
for module in &modules {
|
||||
let id = sanitize(module);
|
||||
lines.push(format!("{id}: {module}"));
|
||||
}
|
||||
|
||||
let mut edges: HashSet<(String, String)> = HashSet::new();
|
||||
for rel in graph.relationships() {
|
||||
if rel.kind() == RelationshipKind::Import {
|
||||
continue;
|
||||
}
|
||||
// Direct module-to-module edge (from merged project deps)
|
||||
if modules.contains(rel.source())
|
||||
&& modules.contains(rel.target())
|
||||
&& rel.source() != rel.target()
|
||||
{
|
||||
edges.insert((rel.source().to_string(), rel.target().to_string()));
|
||||
continue;
|
||||
}
|
||||
let src_mod = name_to_module.get(rel.source());
|
||||
let tgt_mod = name_to_module.get(rel.target());
|
||||
if let (Some(s), Some(t)) = (src_mod, tgt_mod)
|
||||
&& s != t
|
||||
{
|
||||
edges.insert((s.to_string(), t.to_string()));
|
||||
}
|
||||
}
|
||||
|
||||
for (src, tgt) in &edges {
|
||||
for (src, tgt) in graph.module_edges().keys() {
|
||||
lines.push(format!("{} -> {}", sanitize(src), sanitize(tgt)));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user