Skip to content

Annotating newline characters leads to busy looking multi-line span #454

Description

@epage

Take the test case

#[test]
fn span_eol() {
    let source = "#: E112\nif False:\nprint()\n#: E113\nprint()\n";
    let input = &[Group::with_level(Level::ERROR).element(
        Snippet::source(source)
            .line_start(7)
            .fold(false)
            .annotation(AnnotationKind::Primary.span(17..18).label("E112")),
    )];

    let expected_ascii = str![[r#"
   |
 7 |   #: E112
 8 |   if False:
   |  __________^
 9 | | print()
   | |_^ E112
10 |   #: E113
11 |   print()
   |
"#]];
    let renderer = Renderer::plain();
    assert_data_eq!(renderer.render(input), expected_ascii);

    let expected_unicode = str![[r#"
   ╭▸ 
 7 │   #: E112
 8 │   if False:
   │ ┏━━━━━━━━━━┛
 9 │ ┃ print()
   │ ┗━┛ E112
10 │   #: E113
11 │   print()
   ╰╴
"#]];
    let renderer = renderer.decor_style(DecorStyle::Unicode);
    assert_data_eq!(renderer.render(input), expected_unicode);
}

It would be cleaner to annotate the space just after the last character in ascii:

    let expected_ascii = str![[r#"
   |
 7 | #: E112
 8 | if False:
   |          ^ E112
 9 | print()
10 | #: E113
11 | print()
   |
"#]];

or a new-line substitute in unicode

    let expected_unicode = str![[r#"
   ╭▸ 
 7 │ #: E112
 8 │ if False:␤
   │          ━ E112
 9 │ print()
10 │ #: E113
11 │ print()
   ╰╴
"#]];

Identified in astral-sh/ruff#27033

Related issues:

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