brendanzab / codespan

Beautiful diagnostic reporting for text-based programming languages.
Apache License 2.0
1.08k stars 58 forks source link

Allow adding labels to notes #346

Open nolanderc opened 2 years ago

nolanderc commented 2 years ago

Attempts to address #293 by extending each note with an optional list of labels:

error: cycle detected when evaluating constant `A`
  ┌─ one_line.rs:1:1
  │
1 │ const A: u32 = B;
  │ ^^^^^^^^^^^^^^^^^
  │
  = ...which requires evaluating constant `B`...
  ┌─ one_line.rs:2:1
  │
2 │ const B: u32 = A;
  │ -----------------
  │
  = ...which requires evaluating constant `A`
  ┌─ one_line.rs:1:1
  │
1 │ const A: u32 = B;
  │ -----------------
brendanzab commented 1 year ago

Cool, thanks so much! Apologies for the lackluster response time. If labels are attached to the notes, I wonder if it would make sense to indent them to demonstrate the hierarchy?

error: cycle detected when evaluating constant `A`
  ┌─ one_line.rs:1:1
  │
1 │ const A: u32 = B;
  │ ^^^^^^^^^^^^^^^^^
  │
  = ...which requires evaluating constant `B`...
      ┌─ one_line.rs:2:1
      │
    2 │ const B: u32 = A;
      │ -----------------
      │
      = ...which requires evaluating constant `A`
      ┌─ one_line.rs:1:1
      │
    1 │ const A: u32 = B;
      │ -----------------

That might look a bit weird though…

If not I wonder if another solution could be to allow for a series of trailing labels attached to the top level diagnostic that are always rendered in order. 🤔

No worries if you are on other things at the moment.