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

Formatting bug with overlapping lines #21

Closed
Labels
C-enhancementCategory: enhancement E-help-wantedCall for participation: Help is requested to fix this issue
@yoshuawuyts

Description

I was messing around with the basic example, and found some interesting behavior (that doesn't seem to be quite right. Below is the source code + output for a few cases.

update: as I was going through this it seems that there is a clear bug for this. If we start the annotation at either 0 or 1 it offsets. At range 2 it's before the line. But at range 3 it actually pops back to the right location (I think, I'm unsure because of /, but that might just be the right behavior)! Check out cases 4 and 5 for what's going on.

Either way, I hope this report is helpful. Excited this crate exists!

Case 1

Output

error: expected type, found `22`
 --> examples/example.txt:27:11
 |
26 |
 | __-
 | __-
27 | This is an example content of the slice which will be annotated with the list of annotations below.
 | | ^^^^^ Example error annotation
 | ||___________________________________________________________- and here's a warning
 | |_______________________________________- and here's a warning
28 |
 |

Code

use annotate_snippets::display_list::DisplayList;
use annotate_snippets::formatter::DisplayListFormatter;
use annotate_snippets::snippet::{Annotation, AnnotationType, Slice, Snippet, SourceAnnotation};
fn main() {
 let snippet = Snippet {
 title: Some(Annotation {
 label: Some("expected type, found `22`".to_string()),
 id: None,
 annotation_type: AnnotationType::Error,
 }),
 footer: vec![],
 slices: vec![Slice {
 source: r#"
This is an example content of the slice which will be annotated with the list of annotations below.
 "#
 .to_string(),
 line_start: 26,
 origin: Some("examples/example.txt".to_string()),
 fold: false,
 annotations: vec![
 SourceAnnotation {
 label: "Example error annotation".to_string(),
 annotation_type: AnnotationType::Error,
 range: (13, 18),
 },
 SourceAnnotation {
 label: "and here's a warning".to_string(),
 annotation_type: AnnotationType::Warning,
 range: (1, 60),
 },
 SourceAnnotation {
 label: "and here's a warning".to_string(),
 annotation_type: AnnotationType::Warning,
 range: (1, 40),
 },
 ],
 }],
 };
 let dl = DisplayList::from(snippet);
 let dlf = DisplayListFormatter::new(true, false);
 println!("{}", dlf.format(&dl));
}

Case 2

Output

error: expected type, found `22`
 --> examples/example.txt:27:11
 |
26 |
 | __-
27 | This is an example content of the slice which will be annotated with the list of annotations below.
 | | ^^^^^ Example error annotation
 | |___________________________________________________________- and here's a warning
28 |
 |

Code

use annotate_snippets::display_list::DisplayList;
use annotate_snippets::formatter::DisplayListFormatter;
use annotate_snippets::snippet::{Annotation, AnnotationType, Slice, Snippet, SourceAnnotation};
fn main() {
 let snippet = Snippet {
 title: Some(Annotation {
 label: Some("expected type, found `22`".to_string()),
 id: None,
 annotation_type: AnnotationType::Error,
 }),
 footer: vec![],
 slices: vec![Slice {
 source: r#"
This is an example content of the slice which will be annotated with the list of annotations below.
 "#
 .to_string(),
 line_start: 26,
 origin: Some("examples/example.txt".to_string()),
 fold: false,
 annotations: vec![
 SourceAnnotation {
 label: "Example error annotation".to_string(),
 annotation_type: AnnotationType::Error,
 range: (13, 18),
 },
 SourceAnnotation {
 label: "and here's a warning".to_string(),
 annotation_type: AnnotationType::Warning,
 range: (1, 60),
 },
 ],
 }],
 };
 let dl = DisplayList::from(snippet);
 let dlf = DisplayListFormatter::new(true, false);
 println!("{}", dlf.format(&dl));
}

Case 3

Output

error: expected type, found `22`
 --> examples/example.txt:26:1
 |
26 |
 | __-
27 | | This is an example content of the slice which will be annotated with the list of annotations below.
 | |___________________________________________________________- and here's a warning
28 |
 |

Code

use annotate_snippets::display_list::DisplayList;
use annotate_snippets::formatter::DisplayListFormatter;
use annotate_snippets::snippet::{Annotation, AnnotationType, Slice, Snippet, SourceAnnotation};
fn main() {
 let snippet = Snippet {
 title: Some(Annotation {
 label: Some("expected type, found `22`".to_string()),
 id: None,
 annotation_type: AnnotationType::Error,
 }),
 footer: vec![],
 slices: vec![Slice {
 source: r#"
This is an example content of the slice which will be annotated with the list of annotations below.
 "#
 .to_string(),
 line_start: 26,
 origin: Some("examples/example.txt".to_string()),
 fold: false,
 annotations: vec![SourceAnnotation {
 label: "and here's a warning".to_string(),
 annotation_type: AnnotationType::Warning,
 range: (1, 60),
 }],
 }],
 };
 let dl = DisplayList::from(snippet);
 let dlf = DisplayListFormatter::new(true, false);
 println!("{}", dlf.format(&dl));
}

Case 4

The range now starts at index 2.

Output

error: expected type, found `22`
 --> examples/example.txt:27:0
 |
26 |
27 | / This is an example content of the slice which will be
28 | | annotated with the list of annotations below.
 | |____- and here's a warning
29 |
 |

Code

use annotate_snippets::display_list::DisplayList;
use annotate_snippets::formatter::DisplayListFormatter;
use annotate_snippets::snippet::{Annotation, AnnotationType, Slice, Snippet, SourceAnnotation};
fn main() {
 let snippet = Snippet {
 title: Some(Annotation {
 label: Some("expected type, found `22`".to_string()),
 id: None,
 annotation_type: AnnotationType::Error,
 }),
 footer: vec![],
 slices: vec![Slice {
 source: r#"
This is an example content of the slice which will be
annotated with the list of annotations below.
 "#
 .to_string(),
 line_start: 26,
 origin: Some("examples/example.txt".to_string()),
 fold: false,
 annotations: vec![SourceAnnotation {
 label: "and here's a warning".to_string(),
 annotation_type: AnnotationType::Warning,
 range: (2, 60),
 }],
 }],
 };
 let dl = DisplayList::from(snippet);
 let dlf = DisplayListFormatter::new(true, false);
 println!("{}", dlf.format(&dl));
}

Case 5

The range now starts at index 3.

Output

error: expected type, found `22`
 --> examples/example.txt:27:1
 |
26 |
27 | This is an example content of the slice which will be
 | __-
28 | | annotated with the list of annotations below.
 | |____- and here's a warning
29 |
 |

Code

use annotate_snippets::display_list::DisplayList;
use annotate_snippets::formatter::DisplayListFormatter;
use annotate_snippets::snippet::{Annotation, AnnotationType, Slice, Snippet, SourceAnnotation};
fn main() {
 let snippet = Snippet {
 title: Some(Annotation {
 label: Some("expected type, found `22`".to_string()),
 id: None,
 annotation_type: AnnotationType::Error,
 }),
 footer: vec![],
 slices: vec![Slice {
 source: r#"
This is an example content of the slice which will be
annotated with the list of annotations below.
 "#
 .to_string(),
 line_start: 26,
 origin: Some("examples/example.txt".to_string()),
 fold: false,
 annotations: vec![SourceAnnotation {
 label: "and here's a warning".to_string(),
 annotation_type: AnnotationType::Warning,
 range: (3, 60),
 }],
 }],
 };
 let dl = DisplayList::from(snippet);
 let dlf = DisplayListFormatter::new(true, false);
 println!("{}", dlf.format(&dl));
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: enhancement E-help-wantedCall for participation: Help is requested to fix this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /