grace icon indicating copy to clipboard operation
grace copied to clipboard

Assert_failure lib/ansi_renderer/snippet_renderer.ml:114:4

Open N1ark opened this issue 7 months ago • 0 comments

Encountering a weird error when attempting to have two labels, the second one being below the first. I don't know the code base at all so have no idea what is causing this or how to fix it :/ I'm happy to open a PR if anyone has an idea on what's causing this.

Interestingly:

  • if I remove r1, it displays properly (without the foo, of course)
  • if I add a space before bar and offset both indices for r2 by 1, it works properly -- it seems to be related to the fact bar is at the start of the line, maybe?

Expected output:

error: err
    ┌─ unknown:1:1
  1 │    foo
    │    ^^^ e1
  2 │
  3 │ ╭  bar {
  4 │ │  }
    │ ╰──' e2
  5 │

Reproducing example:


let () =
  let open Grace in
  let open Diagnostic in
  let content = {|foo

bar {
}
|} in
  let r1 =
    Range.create
      ~source:(`String { name = None; content })
      (Byte_index.of_int 0) (Byte_index.of_int 3)
  in
  let r2 =
    Range.create
      ~source:(`String { name = None; content })
      (Byte_index.of_int 5) (Byte_index.of_int 12)
  in
  let labels =
    [
      Label.createf ~range:r1 ~priority:Primary "e1";
      Label.createf ~range:r2 ~priority:Secondary "e2";
    ]
  in
  let diag = Diagnostic.createf ~labels Error "err" in
  Fmt.pr "%a" (Grace_ansi_renderer.pp_diagnostic ()) diag

N1ark avatar Jun 06 '25 22:06 N1ark