MCPcopy Create free account
hub / github.com/ScriptedAlchemy/tracedecay / nested_cell_str

Function nested_cell_str

src/mcp/tools/render.rs:443–473  ·  view source on GitHub ↗

Renders a nested JSON value into a single table cell without dumping raw JSON. Arrays of objects become `name (file:line)`-style summaries; plain objects become compact `k=v` strings; arrays of scalars are comma-joined.

(v: &Value)

Source from the content-addressed store, hash-verified

441/// JSON. Arrays of objects become `name (file:line)`-style summaries; plain
442/// objects become compact `k=v` strings; arrays of scalars are comma-joined.
443fn nested_cell_str(v: &Value) -> String {
444 const MAX_ITEMS: usize = 3;
445
446 match v {
447 Value::Array(arr) => {
448 if arr.is_empty() {
449 return "none".to_string();
450 }
451 let shown: Vec<String> = arr
452 .iter()
453 .take(MAX_ITEMS)
454 .map(|e| match e {
455 Value::Object(obj) => summarize_object(obj),
456 _ => scalar_str(e),
457 })
458 .collect();
459 if arr.len() > MAX_ITEMS {
460 format!(
461 "{} … (+{} more, {} total)",
462 shown.join("; "),
463 arr.len() - MAX_ITEMS,
464 arr.len()
465 )
466 } else {
467 shown.join("; ")
468 }
469 }
470 Value::Object(obj) => summarize_object(obj),
471 _ => scalar_str(v),
472 }
473}
474
475/// Compact one-line summary of an object for a table cell. Prefers a
476/// `name (file:line)` shape when those keys exist, else `k=v` pairs.

Callers 1

cell_strFunction · 0.85

Calls 5

summarize_objectFunction · 0.85
scalar_strFunction · 0.85
collectMethod · 0.80
is_emptyMethod · 0.45
takeMethod · 0.45

Tested by

no test coverage detected