annotate-snippets-rs icon indicating copy to clipboard operation
annotate-snippets-rs copied to clipboard

Problem with Unix line feed annotation using empty ranges

Open Volham22 opened this issue 1 year ago • 0 comments

Hello, thanks for your amazing work on this crate!

I recently encountered a problem while trying to annotate Unix line feeds (\n). When annotating line feeds with an empty Range, I got the following error:

error: bad
--> test.txt:1:1
 |
 |

This looks like a bug because doing the same thing on letters or digits works as expected:

error: bad
 --> test.txt:1:1
  |
1 | 111
  | ^
  |

Also, giving a non-empty Range solves the problem and outputs the annotation as expected:

error: bad
 --> test.txt:1:1
  |
1 | ...
  | ^
  |

Here is the code used to reproduce the problem (which occurs with the latest release). test.txt is a simple text file containing only Unix line feeds (\n):

use annotate_snippets::{Level, Renderer, Snippet};

pub fn reproduce_bug() {
    let renderer = Renderer::styled();
    let message = Level::Error.title("bad").snippet(
        Snippet::source(include_str!("../test.txt"))
            .origin("test.txt")
            .fold(true)
            .annotation(Level::Error.span(0..0)),
    );
    anstream::println!("{}", renderer.render(message));
}

Volham22 avatar Jul 09 '24 09:07 Volham22