MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / node_label

Function node_label

atomic-cli/src/commands/query/mod.rs:552–610  ·  view source on GitHub ↗

Build a human-readable label for a node in DOT output.

(node: &KgNode)

Source from the content-addressed store, hash-verified

550
551/// Build a human-readable label for a node in DOT output.
552fn node_label(node: &KgNode) -> String {
553 let kind = node.kind.to_lowercase();
554 match kind.as_str() {
555 "module" => {
556 // Last path component + trailing slash
557 let last = node
558 .label
559 .rsplit('/')
560 .find(|s| !s.is_empty())
561 .unwrap_or(&node.label);
562 format!("{}/", last)
563 }
564 "file" => {
565 // Filename, optionally with match count
566 let filename = node.label.rsplit('/').next().unwrap_or(&node.label);
567 if let Some(ref meta) = node.metadata {
568 if let Some(matches) = meta.get("content_matches").and_then(|v| v.as_u64()) {
569 return format!("{}\n{} matches", filename, matches);
570 }
571 }
572 filename.to_string()
573 }
574 "entity" => {
575 // Label + kind/line info from metadata
576 let mut label = node.label.clone();
577 if let Some(ref meta) = node.metadata {
578 let ent_kind = meta.get("kind").and_then(|v| v.as_str());
579 let line = meta.get("line").and_then(|v| v.as_u64());
580 let end_line = meta.get("end_line").and_then(|v| v.as_u64());
581 if let (Some(k), Some(l)) = (ent_kind, line) {
582 if let Some(el) = end_line {
583 label = format!("{}\n{} L{}-{}", label, k, l, el);
584 } else {
585 label = format!("{}\n{} L{}", label, k, l);
586 }
587 }
588 }
589 label
590 }
591 "change" => {
592 // Short hash + optional summary excerpt
593 let mut label = node.label.clone();
594 if let Some(ref summary) = node.summary {
595 let excerpt: String = summary.chars().take(30).collect();
596 label = format!("{}\n{}", label, excerpt);
597 }
598 label
599 }
600 _ => {
601 // Everything else: label truncated to 40 chars
602 if node.label.len() > 40 {
603 let truncated: String = node.label.chars().take(37).collect();
604 format!("{}...", truncated)
605 } else {
606 node.label.clone()
607 }
608 }
609 }

Callers 1

emit_dotFunction · 0.85

Calls 7

as_u64Method · 0.80
getMethod · 0.65
as_strMethod · 0.45
is_emptyMethod · 0.45
nextMethod · 0.45
cloneMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected