Skip to content

Patch highlighting is shifted when source contains \t #371

@scrabsha

Description

@scrabsha

The following test:

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

use snapbox::{assert_data_eq, file};

#[test]
fn test() {
    let report = &[Level::ERROR
        .primary_title("<sample error message>")
        .element(
            Snippet::source(
                "\t\t\tts.into_iter().map(|t| {\n\t\t\t\t(is_true, t)\n\t\t\t}).flatten()\n",
            )
            .line_start(6)
            .path("<sample path>")
            .patch(Patch::new(17..50, "")),
        )];

    let expected_ascii = file!["regression.ascii.term.svg": TermSvg];
    let renderer = Renderer::styled();
    assert_data_eq!(renderer.render(report), expected_ascii);
}

To render like this (image generated using v0.12.10):

Image

However, using the main version of annotate-snippets, it renders like this:

Image

I bissected, and it looks like this was introduced by 3d365cc / #357.

Is that intended?

Initial repro (with v0.12.10 / good) rendering can be found in commit 69e171c (on my fork of the repo).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions