Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Off-by-one error in multiline error highlights #41

Closed
@digama0

Description

@digama0

In both cases, the highlight begins at lettere and ends at letterl. In the one-line case, it is correct:

error: oops --> <current file>:1:6  |1 | abcd efgh ijkl mnop  |      ^^^^^^^^^ oops  |

But in multiple lines it is off by one - the end pointer points to one past the end rather than the last character of the highlight:

error: oops --> <current file>:1:6  |1 |   abcd efgh  |  ______^2 | | ijkl mnop  | |_____^ oops  |

I could propose code but I'm not sure I'll get all the details of continuations right since I haven't used those and am not certain of the desired behavior. Here's the issue presented as a test case.

use annotate_snippets::{display_list::DisplayList, snippet};use snippet::Snippet;#[test]fnwith_space_works(){let snippets =Snippet{title:Some(snippet::Annotation{id:None,label:Some("oops"),annotation_type: snippet::AnnotationType::Error,}),footer:vec![],slices:vec![snippet::Slice{            source:"abcd efgh ijkl mnop",            line_start:1,            origin:Some("<current file>"),            annotations: vec![snippet::SourceAnnotation{                range:(5,14),                label:"oops",                annotation_type: snippet::AnnotationType::Error,}],            fold:true,}],opt:Default::default(),};let expected =r#"error: oops --> <current file>:1:6  |1 | abcd efgh ijkl mnop  |      ^^^^^^^^^ oops  |"#;assert_eq!(DisplayList::from(snippets).to_string(), expected);}#[test]fnwith_newline_fails(){let snippets =Snippet{title:Some(snippet::Annotation{id:None,label:Some("oops"),annotation_type: snippet::AnnotationType::Error,}),footer:vec![],slices:vec![snippet::Slice{            source:"abcd efgh\nijkl mnop",            line_start:1,            origin:Some("<current file>"),            annotations: vec![snippet::SourceAnnotation{                range:(5,14),                label:"oops",                annotation_type: snippet::AnnotationType::Error,}],            fold:true,}],opt:Default::default(),};let expected =r#"error: oops --> <current file>:1:6  |1 |   abcd efgh  |  ______^2 | | ijkl mnop  | |____^ oops  |"#;assert_eq!(DisplayList::from(snippets).to_string(), expected);}

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


      [8]ページ先頭

      ©2009-2025 Movatter.jp