You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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};fnmain(){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};fnmain(){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};fnmain(){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};fnmain(){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 beannotated 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};fnmain(){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 beannotated 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));}
The text was updated successfully, but these errors were encountered:
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
Code
Case 2
Output
Code
Case 3
Output
Code
Case 4
The range now starts at index 2.
Output
Code
Case 5
The range now starts at index 3.
Output
Code
The text was updated successfully, but these errors were encountered: