-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Weird formatting with fold: true
#56
Comments
Yeah, it's intentional. It could be configurable around |
Okay. Though I am still not quite sure why this is intentional. What is the advantage of displaying the first four lines of the file (only) if the error is far away from those? |
One thing is printing the first four lines, I can live with that however it works. My biggest problem is, that for certain inputs, the crate prints two empty lines, nothing more. Example, may or may not require Windowsuse annotate_snippets::{
display_list::{DisplayList, FormatOptions},
snippet::{Annotation, AnnotationType, Slice, Snippet, SourceAnnotation},
};
fn main() {
let source = "foo\r\nbar\r\n\r\nfoo\r\nbar\r\nbaz\r\n\r\nfoo\r\nbar\r\nbaz";
println!("String in range: {}", &source[9..28]);
println!("annotate-snippets output:");
let snippet = Snippet {
title: Some(Annotation {
label: Some("error"),
id: None,
annotation_type: AnnotationType::Error,
}),
footer: vec![],
slices: vec![Slice {
line_start: 0,
source: &source,
origin: None,
fold: true,
annotations: vec![SourceAnnotation {
label: "label",
annotation_type: AnnotationType::Error,
range: (9, 28),
}],
}],
opt: FormatOptions {
color: true,
..Default::default()
},
};
println!("{}", &DisplayList::from(snippet))
} I strongly hope this is not intentional. |
The latter issue is that the crate doesn't handle As for the initial 4 lines. It is intended to show the above context, but I can see how it is useless in your example. My intent was to show the begging of a snippet in case the snippet is long, and then cut to the part where the error occurs. It's here: https://github.com/rust-lang/annotate-snippets-rs/blob/master/src/display_list/from_snippet.rs#L189 If your first annotation is in line 9, then why do you include the first 8 lines at all if not for context? |
When rendering an annotation with
fold: true
the first 4 lines get rendered if the source has more than 7 lines.If the source has 7 or less lines, the first lines do not get rendered.
Example with
source = "\n\n\n\n\n\n\nFoo"
:Example with
source = "\n\n\n\n\n\n\n\nFoo"
:Minimal example:
I am not sure if this is intended. In either case there should probably some way to disable this behavior.
The text was updated successfully, but these errors were encountered: