silcrow 0.2.0

Deterministic CLI for a citable, checkable graph of laws in a git tree.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
use anyhow::Result;
use serde_json::{json, Value};
use std::collections::{BTreeMap, HashMap};
use std::fmt::Write as _;
use std::path::{Path, PathBuf};

use crate::check;
use crate::follow::FollowIndex;
use crate::graph::Graph;
use crate::marker::{self, MarkerAddr};
use crate::parse::{self, Scan};
use crate::policy::ProjectPolicy;
use crate::span::{self, CodeFile};
use crate::walk;
use crate::workspace::{ProjectRef, Workspace};

/// How many callees the fan-in lists.
const TOP_CALLEES: usize = 10;

pub fn run(ws: &Workspace, project: &ProjectRef, json: bool) -> Result<()> {
    // § a432vkc9m@k8yn3
    let root = project.dir.as_path();
    let scan = parse::scan_root(root)?;
    let code = CodeFile::read_all(root)?;
    let tests = crate::policy::TestPaths::at(root)?;
    let follow = FollowIndex::from_files(&code, &tests);
    let stats = Stats {
        notes: note_stats(&scan),
        pins: pin_stats(&scan, &code, &follow),
        files: files_per_language(&code),
        coverage: coverage(&code, &follow, &tests, &crate::walk::Project::at(root)?),
        resolved: resolved_references(ws, project, &scan)?,
        oldest_draft: oldest_draft(root, &scan),
    };
    // § v0nc7pmm7@sxnw4
    if json {
        println!("{}", serde_json::to_string_pretty(&stats.json())?);
    } else {
        print!("{}", stats.table());
    }
    // § end v0nc7pmm7
    Ok(())
}

struct Stats {
    notes: BTreeMap<String, NoteStats>,
    pins: PinStats,
    files: BTreeMap<&'static str, usize>,
    coverage: BTreeMap<(&'static str, bool), Coverage>,
    resolved: usize,
    oldest_draft: Option<OldestDraft>,
}

/// The draft whose line the earliest commit adds: its address, that commit's date and its age.
struct OldestDraft {
    address: String,
    since: String,
    age: String,
}

fn oldest_draft(root: &Path, scan: &Scan) -> Option<OldestDraft> {
    // § a432vkc9m.b@278sn
    let drafts = crate::list::drafts(&scan.laws);
    let ages = crate::meta::draft_ages(root, &drafts)?;
    drafts
        .iter()
        .zip(ages)
        .filter_map(|(draft, age)| match age? {
            (Some(since), Some(age)) => Some(OldestDraft {
                address: draft.address(),
                since,
                age,
            }),
            _ => None,
        })
        .min_by(|a, b| a.since.cmp(&b.since))
}

/// The lines of one language and kind of code that are not blank, those inside the span of a
/// marker, and those some pin reads.
#[derive(Default, Clone)]
struct Coverage {
    lines: usize,
    zoned: usize,
    read: usize,
}

impl Coverage {
    fn add(&mut self, other: &Coverage) {
        self.lines += other.lines;
        self.zoned += other.zoned;
        self.read += other.read;
    }

    fn share(&self, n: usize) -> Option<f64> {
        (self.lines > 0).then(|| (n as f64 * 1000.0 / self.lines as f64).round() / 10.0)
    }

    fn json(&self) -> Value {
        json!({
            "lines": self.lines,
            "zoned": self.zoned,
            "read": self.read,
            "zoned_pct": self.share(self.zoned),
            "read_pct": self.share(self.read),
        })
    }
}

#[derive(Default, Clone)]
struct NoteStats {
    laws: usize,
    /// Laws neither struck nor drafts.
    active_laws: usize,
    clauses: usize,
    /// Struck clauses, and the clauses of a struck law.
    struck: usize,
    active: usize,
    /// Draft addresses: draft laws, and active clauses that are drafts.
    drafts: usize,
    /// Active laws written `§!`, drafts included.
    public: usize,
    words: usize,
    words_max: usize,
    longest: Option<String>,
    /// Active clauses and carrying sentences over the word count at which `check` warns.
    over: usize,
    /// The sentence, the body under the head and the clause bodies of the active text.
    bytes: usize,
}

impl NoteStats {
    fn add(&mut self, other: &NoteStats) {
        self.laws += other.laws;
        self.active_laws += other.active_laws;
        self.clauses += other.clauses;
        self.struck += other.struck;
        self.active += other.active;
        self.drafts += other.drafts;
        self.public += other.public;
        self.words += other.words;
        self.bytes += other.bytes;
        self.over += other.over;
        if other.words_max > self.words_max {
            self.words_max = other.words_max;
            self.longest = other.longest.clone();
        }
    }

    fn words_mean(&self) -> Option<f64> {
        mean(self.words, self.active)
    }

    fn json(&self) -> Value {
        json!({
            "laws": self.laws,
            "clauses": self.clauses,
            "struck_clauses": self.struck,
            "active_clauses": self.active,
            "drafts": self.drafts,
            "public": self.public,
            "words_mean": self.words_mean(),
            "words_max": self.words_max,
            "longest": self.longest,
            "over_word_limit": self.over,
            "bytes": self.bytes,
        })
    }
}

fn note_stats(scan: &Scan) -> BTreeMap<String, NoteStats> {
    // § a432vkc9m@ah38q
    let mut out: BTreeMap<String, NoteStats> = BTreeMap::new();
    for law in &scan.laws {
        let note = out.entry(law.loc.path.display().to_string()).or_default();
        note.laws += 1;
        if !law.struck {
            note.bytes += law.pin_text().len();
            // § pxmeee9ra.e@2ggss
            note.drafts += usize::from(law.draft);
            note.public += usize::from(law.public);
            note.active_laws += usize::from(!law.draft);
        }
        for clause in &law.clauses {
            note.clauses += 1;
            if law.struck || clause.struck {
                note.struck += 1;
                continue;
            }
            note.active += 1;
            // § pxmeee9ra.e@y40x1
            note.drafts += usize::from(clause.draft);
            // § end pxmeee9ra.e
            note.bytes += clause.body.len();
            let words = clause.body.split_whitespace().count();
            note.words += words;
            if words > note.words_max {
                note.words_max = words;
                note.longest = Some(match &clause.letter {
                    Some(letter) => format!("{}.{letter}", law.id),
                    None => law.id.clone(),
                });
            }
        }
    }
    for (_, loc, words) in check::text_lengths(scan) {
        if words > check::WARN_WORDS {
            out.entry(loc.path.display().to_string()).or_default().over += 1;
        }
    }
    out
}

/// A body a pin follows, by its name and file.
type Body = (String, PathBuf);

#[derive(Default)]
struct PinStats {
    markers: usize,
    pinned: usize,
    laws: BTreeMap<String, LawPins>,
    /// Per followed body, by name and file: the pins that follow it and its 1-based line.
    fan_in: BTreeMap<Body, (usize, usize)>,
}

#[derive(Default)]
struct LawPins {
    markers: usize,
    /// Per pin whose span the file delimits: the bytes it reads and the bodies it follows.
    read: Vec<usize>,
    callees: Vec<usize>,
}

impl LawPins {
    fn json(&self, law: &str) -> Value {
        json!({
            "law": law,
            "markers": self.markers,
            "pins": self.read.len(),
            "bytes_mean": mean(self.read.iter().sum(), self.read.len()),
            "bytes_max": self.read.iter().max(),
            "callees_mean": mean(self.callees.iter().sum(), self.callees.len()),
            "callees_max": self.callees.iter().max(),
        })
    }
}

fn pin_stats(scan: &Scan, code: &[CodeFile], follow: &FollowIndex) -> PinStats {
    // § a432vkc9m@82vh1
    let alias: HashMap<&str, &str> = scan
        .laws
        .iter()
        .flat_map(|law| law.aliases.iter().map(|a| (a.as_str(), law.id.as_str())))
        .collect();
    let law_of = |addr: &MarkerAddr| {
        let id = alias.get(addr.id.as_str()).copied().unwrap_or(&addr.id);
        match &addr.project {
            Some(project) => format!("{project}:{}", addr.id),
            None => id.to_string(),
        }
    };
    let texts: HashMap<&Path, &str> = code
        .iter()
        .map(|f| (f.rel.as_path(), f.text.as_str()))
        .collect();
    let mut out = PinStats::default();
    for file in code {
        for (_, line) in file.marker_lines() {
            for addr in marker::markers_in_line(line) {
                out.markers += 1;
                out.pinned += usize::from(addr.digest.is_some());
                out.laws.entry(law_of(&addr)).or_default().markers += 1;
            }
        }
        let markers = file.span_markers();
        for m in markers.iter().filter(|m| m.addr.digest.is_some()) {
            let punch = span::punch_of(&markers, m.line);
            let prefix = file.prefix(m.start, m.end);
            let callees = follow.followed_callees(&file.rel, m.start, m.end, &punch, &prefix);
            let mut bodies: BTreeMap<Body, Vec<(usize, usize)>> = BTreeMap::new();
            for callee in callees {
                bodies
                    .entry((callee.name, callee.path))
                    .or_default()
                    .push((callee.start, callee.end));
            }
            let mut read = (m.end - m.start) - covered(punch);
            for (start, end, holes) in prefix {
                read += (end - start) - covered(holes);
            }
            for ((name, path), stretches) in &bodies {
                read += covered(stretches.clone());
                let first = stretches
                    .iter()
                    .map(|s| s.0)
                    .min()
                    .expect("a body has a stretch");
                let line = texts
                    .get(path.as_path())
                    .and_then(|t| t.get(..first))
                    .map_or(1, |before| before.matches('\n').count() + 1);
                out.fan_in
                    .entry((name.clone(), path.clone()))
                    .or_insert((0, line))
                    .0 += 1;
            }
            let law = out.laws.entry(law_of(&m.addr)).or_default();
            law.read.push(read);
            law.callees.push(bodies.len());
        }
    }
    out
}

/// The bytes the union of `ranges` covers.
fn covered(mut ranges: Vec<(usize, usize)>) -> usize {
    ranges.sort();
    let (mut total, mut reach) = (0, 0);
    for (start, end) in ranges {
        let start = start.max(reach);
        if end > start {
            total += end - start;
            reach = end;
        }
    }
    total
}

/// Per language and per kind, test code or not, the non-blank lines of the walked files, those a
/// marker's span holds, and those a pin reads: its span, the code before it, an import line or a
/// body it follows.
fn coverage(
    code: &[CodeFile],
    follow: &FollowIndex,
    tests: &crate::policy::TestPaths,
    project: &crate::walk::Project,
) -> BTreeMap<(&'static str, bool), Coverage> {
    // § a432vkc9m.a@1jvnm
    let mut zoned: HashMap<&Path, Vec<(usize, usize)>> = HashMap::new();
    let mut read: HashMap<PathBuf, Vec<(usize, usize)>> = HashMap::new();
    for file in code {
        let markers = file.span_markers();
        for m in &markers {
            let punch = span::punch_of(&markers, m.line);
            let prefix = file.prefix(m.start, m.end);
            let span = outside_holes(m.start, m.end, &punch);
            zoned.entry(&file.rel).or_default().extend(&span);
            let own = read.entry(file.rel.clone()).or_default();
            own.extend(span);
            for (start, end, holes) in &prefix {
                own.extend(outside_holes(*start, *end, holes));
            }
            own.extend(follow.pin_import_bytes(&file.rel, m.start, m.end, &punch, &prefix));
            for callee in follow.followed_callees(&file.rel, m.start, m.end, &punch, &prefix) {
                read.entry(callee.path)
                    .or_default()
                    .push((callee.start, callee.end));
            }
        }
    }
    let mut out: BTreeMap<(&'static str, bool), Coverage> = BTreeMap::new();
    for file in code {
        if project.is_note(&file.rel) || file.rel == Path::new("AGENTS.md") {
            continue;
        }
        let zoned = union_stretches(zoned.remove(file.rel.as_path()).unwrap_or_default());
        let read = union_stretches(read.remove(&file.rel).unwrap_or_default());
        // § one kwxna1ebv.c@wka2m
        let in_tests = tests.holds(&file.rel);
        let test_rows = file.cfg_test_rows();
        let lang = file.lang.map_or("other", |lang| lang.id);
        let mut start = 0;
        for (row, piece) in file.text.split_inclusive('\n').enumerate() {
            let line = (start, start + piece.len());
            start += piece.len();
            if piece.trim().is_empty() {
                continue;
            }
            let test = in_tests || test_rows.iter().any(|&(a, b)| a <= row && row <= b);
            let entry = out.entry((lang, test)).or_default();
            entry.lines += 1;
            entry.zoned += usize::from(touches_line(&zoned, line));
            entry.read += usize::from(touches_line(&read, line));
        }
    }
    out
}

/// The stretches of `start..end` outside `holes`.
fn outside_holes(start: usize, end: usize, holes: &[(usize, usize)]) -> Vec<(usize, usize)> {
    let mut holes = holes.to_vec();
    holes.sort();
    let mut out = Vec::new();
    let mut from = start;
    for (hole_start, hole_end) in holes {
        if hole_start > from {
            out.push((from, hole_start.min(end)));
        }
        from = from.max(hole_end);
        if from >= end {
            break;
        }
    }
    if from < end {
        out.push((from, end));
    }
    out
}

/// The union of `ranges` as sorted disjoint stretches.
fn union_stretches(mut ranges: Vec<(usize, usize)>) -> Vec<(usize, usize)> {
    ranges.sort();
    let mut out: Vec<(usize, usize)> = Vec::new();
    for (start, end) in ranges {
        match out.last_mut() {
            Some(last) if start <= last.1 => last.1 = last.1.max(end),
            _ => out.push((start, end)),
        }
    }
    out
}

/// Whether the sorted disjoint `stretches` share a byte with `line`.
fn touches_line(stretches: &[(usize, usize)], line: (usize, usize)) -> bool {
    let at = stretches.partition_point(|&(_, end)| end <= line.0);
    stretches.get(at).is_some_and(|&(start, _)| start < line.1)
}

fn files_per_language(code: &[CodeFile]) -> BTreeMap<&'static str, usize> {
    // § a432vkc9m@m4qq4
    let mut out = BTreeMap::new();
    for file in code {
        *out.entry(file.lang.map_or("other", |lang| lang.id))
            .or_default() += 1;
    }
    out
}

/// The addresses `check` counts as resolved, read by the same evaluation of the graph.
fn resolved_references(ws: &Workspace, project: &ProjectRef, scan: &Scan) -> Result<usize> {
    // § a432vkc9m@emqvw
    let root = project.dir.as_path();
    let policy = ProjectPolicy::from_root(root).map_err(anyhow::Error::msg)?;
    let scans = ws.law_scans(&project.key)?;
    let report = check::evaluate(
        scan,
        &Graph::from_scan(scan),
        0,
        &policy,
        &walk::Project::at(root)?.notes,
        &check::Others::from_scans(&scans),
    );
    Ok(report.ok.len())
}

fn code_kind(test: bool) -> &'static str {
    if test {
        "test"
    } else {
        "source"
    }
}

fn mean(sum: usize, n: usize) -> Option<f64> {
    (n > 0).then(|| (sum as f64 / n as f64 * 10.0).round() / 10.0)
}

impl Stats {
    fn total(&self) -> NoteStats {
        let mut total = NoteStats::default();
        for note in self.notes.values() {
            total.add(note);
        }
        total
    }

    /// Per law, the one whose pins read the most bytes first.
    fn laws_by_read(&self) -> Vec<(&String, &LawPins)> {
        let mut laws: Vec<_> = self.pins.laws.iter().collect();
        laws.sort_by_key(|(law, pins)| (std::cmp::Reverse(pins.read.iter().max().copied()), *law));
        laws
    }

    fn top_callees(&self) -> Vec<(&Body, &(usize, usize))> {
        let mut callees: Vec<_> = self.pins.fan_in.iter().collect();
        callees.sort_by_key(|(key, (pins, _))| (std::cmp::Reverse(*pins), *key));
        callees.truncate(TOP_CALLEES);
        callees
    }

    /// The markers per active law, drafts aside.
    fn markers_per_law(&self) -> Option<f64> {
        mean(self.pins.markers, self.total().active_laws)
    }

    /// Per kind, source or test code, the totals over every language Silcrow parses but Markdown, then each
    /// language and kind.
    fn coverage_rows(&self) -> Vec<(String, &'static str, Coverage)> {
        let mut rows = Vec::new();
        for test in [false, true] {
            let mut total = Coverage::default();
            for ((lang, t), c) in &self.coverage {
                if *t == test && !matches!(*lang, "markdown" | "other") {
                    total.add(c);
                }
            }
            rows.push(("code".to_string(), code_kind(test), total));
        }
        for ((lang, test), c) in &self.coverage {
            rows.push(((*lang).to_string(), code_kind(*test), c.clone()));
        }
        rows
    }

    fn coverage_json(&self) -> Value {
        let rows: Vec<Value> = self
            .coverage_rows()
            .into_iter()
            .map(|(lang, kind, c)| {
                let mut value = c.json();
                value["language"] = json!(lang);
                value["kind"] = json!(kind);
                value
            })
            .collect();
        json!({ "markers_per_law": self.markers_per_law(), "rows": rows })
    }

    fn json(&self) -> Value {
        let notes: Vec<Value> = self
            .notes
            .iter()
            .map(|(path, note)| {
                let mut value = note.json();
                value["path"] = json!(path);
                value
            })
            .collect();
        json!({
            "laws": {
                "notes": notes,
                "total": self.total().json(),
                "oldest_draft": self.oldest_draft.as_ref().map(|d| json!({
                    "address": d.address,
                    "since": d.since,
                    "age": d.age,
                })),
            },
            "pins": {
                "markers": self.pins.markers,
                "pinned": self.pins.pinned,
                "bare": self.pins.markers - self.pins.pinned,
                "laws": self.laws_by_read().iter().map(|(law, pins)| pins.json(law)).collect::<Vec<_>>(),
                "top_callees": self.top_callees().iter().map(|((name, path), (pins, line))| json!({
                    "name": name,
                    "path": path.display().to_string(),
                    "line": line,
                    "pins": pins,
                })).collect::<Vec<_>>(),
            },
            "coverage": self.coverage_json(),
            "project": {
                "files": self.files,
                "references_resolved": self.resolved,
            },
        })
    }

    fn table(&self) -> String {
        let opt = |v: Option<f64>| v.map_or("-".to_string(), |v| format!("{v:.1}"));
        let max = |v: Option<&usize>| v.map_or("-".to_string(), usize::to_string);
        let mut out = String::new();
        let total = self.total();
        let width = self
            .notes
            .keys()
            .map(String::len)
            .fold("total".len(), usize::max);
        let _ = writeln!(out, "Laws");
        let _ = writeln!(
            out,
            "  {:<width$}  {:>5}  {:>6}  {:>7}  {:>6}  {:>6}  {:>6}  {:>10}  {:>9}  {:<12}  {:>7}  {:>7}",
            "note",
            "laws",
            "public",
            "clauses",
            "struck",
            "active",
            "drafts",
            "words mean",
            "words max",
            "longest",
            format!("over {}", check::WARN_WORDS),
            "bytes"
        );
        for (path, note) in self.notes.iter().chain([(&"total".to_string(), &total)]) {
            let _ = writeln!(
                out,
                "  {:<width$}  {:>5}  {:>6}  {:>7}  {:>6}  {:>6}  {:>6}  {:>10}  {:>9}  {:<12}  {:>7}  {:>7}",
                path,
                note.laws,
                note.public,
                note.clauses,
                note.struck,
                note.active,
                note.drafts,
                opt(note.words_mean()),
                note.words_max,
                note.longest.as_deref().unwrap_or("-"),
                note.over,
                note.bytes
            );
        }
        if let Some(d) = &self.oldest_draft {
            let _ = writeln!(
                out,
                "  oldest draft § {} since {}, {}",
                d.address, d.since, d.age
            );
        }
        let _ = writeln!(
            out,
            "\nPins\n  {} marker(s), {} pinned, {} bare",
            self.pins.markers,
            self.pins.pinned,
            self.pins.markers - self.pins.pinned
        );
        let laws = self.laws_by_read();
        let width = laws
            .iter()
            .map(|(law, _)| law.len())
            .fold("law".len(), usize::max);
        let _ = writeln!(
            out,
            "  {:<width$}  {:>7}  {:>4}  {:>10}  {:>9}  {:>12}  {:>11}",
            "law", "markers", "pins", "bytes mean", "bytes max", "callees mean", "callees max"
        );
        for (law, pins) in &laws {
            let _ = writeln!(
                out,
                "  {:<width$}  {:>7}  {:>4}  {:>10}  {:>9}  {:>12}  {:>11}",
                law,
                pins.markers,
                pins.read.len(),
                opt(mean(pins.read.iter().sum(), pins.read.len())),
                max(pins.read.iter().max()),
                opt(mean(pins.callees.iter().sum(), pins.callees.len())),
                max(pins.callees.iter().max())
            );
        }
        let pct = |v: Option<f64>| v.map_or("-".to_string(), |v| format!("{v:.1}%"));
        let _ = writeln!(
            out,
            "\nCoverage\n  {} marker(s) per active law\n  {:<12}  {:<6}  {:>8}  {:>7}  {:>7}",
            opt(self.markers_per_law()),
            "language",
            "kind",
            "lines",
            "zoned",
            "read"
        );
        for (lang, kind, c) in self.coverage_rows() {
            let _ = writeln!(
                out,
                "  {:<12}  {:<6}  {:>8}  {:>7}  {:>7}",
                lang,
                kind,
                c.lines,
                pct(c.share(c.zoned)),
                pct(c.share(c.read))
            );
        }
        let _ = writeln!(out, "\nCallees the most pins follow");
        for ((name, path), (pins, line)) in self.top_callees() {
            let _ = writeln!(out, "  {pins:>5}  {name}  {}:{line}", path.display());
        }
        let files: Vec<String> = self
            .files
            .iter()
            .map(|(lang, n)| format!("{lang} {n}"))
            .collect();
        let _ = writeln!(
            out,
            "\nProject\n  files walked: {}\n  {} reference(s) resolved",
            files.join(", "),
            self.resolved
        );
        out
    }
}