brettkolodny / gleam-hug

A package for creating helpful, and pretty CLI messages.
25 stars 1 forks source link

Errors spanning multiple lines do not get underlined correctly #3

Closed MystPi closed 9 months ago

MystPi commented 9 months ago

First off, this library has been a huge help to me and I'm very thankful for it!

I have recently discovered a bug in errors spanning multiple lines. Here is an example:

pub fn main() {
  let test_str = "if (let
x = 1 y = 2 z = 3 in x) 1 else 2"

  hug.error(
    test_str,
    in: "test",
    from: #(1, 5),
    to: #(2, 23),
    message: "invalid syntax",
    hint: "blah",
  )
  |> io.println
}

This is the output:

error: invalid syntax
  ┌─ test:1:5
  │
1 │ if (let
  │     ~~~
2 │ x = 1 y = 2 z = 3 in x) 1 else 2
  │ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  │

? blah

The issue is that the red underline should stop after the closing ), according to the error position given. Like this:

error: invalid syntax
  ┌─ test:1:5
  │
1 │ if (let
  │     ~~~
2 │ x = 1 y = 2 z = 3 in x) 1 else 2
  │ ~~~~~~~~~~~~~~~~~~~~~~~
  │

? blah

However, the underline continues to the end of the second line, regardless of when it is supposed to stop.

I am wondering if this is a bug in the library or a problem on my end? I am using the latest available version of hug: 0.1.1.