Skip to content

Line not displayed when first span character is a line feed #130

Closed
@Volham22

Description

@Volham22

Hello,

Thanks for all your work on this project!

Problem

I recently discovered an issue while using annotate_snippets version 0.11.3 with the following code:

    let message = Level::Error.title("dummy").snippet(
        Snippet::source(
            r"foo
bar
baz
            ",
        )
        .fold(true)
        .annotation(Level::Error.span(4..11)),
    );
    let renderer = Renderer::styled();
    anstream::println!("{}", renderer.render(message));

test.txt

foo
bar
baz

The problem is that when a span starts with a line feed (\n), the entire following line isn't annotated and is sort of ignored. We can clearly see in the output below that the annotation is somehow truncated. While this isn't a blocking problem for us, we wanted to share our finding as this looks like a bug.

Actual output

This code produces the following output:

$ cargo r
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.01s
     Running `target/debug/error_message_tests`
error: dummy
  |
3 | | baz
  | |___^
  |

Expected output

We can get the following output by moving the annotation's span to the previous byte (3..11).

$ cargo r
   Compiling error_message_tests v0.1.0 (/home/machu/work/error_message_tests)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.18s
     Running `target/debug/error_message_tests`
error: dummy
  |
1 |   foo
  |  ____^
2 | | bar
3 | | baz
  | |___^
  |

Thanks for your time!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions