annotate-snippets-rs
annotate-snippets-rs copied to clipboard
__ gets lost from labels
The starlark-rust library uses this code, specifically at https://github.com/facebookexperimental/starlark-rust/blob/13bec61a44dd2ec268403e1d6da4401ea76a3f12/starlark/src/errors/mod.rs#L205-L219. The relevant fragment is:
let snippet = Snippet {
title: Some(Annotation {
label: Some(annotation_label),
id: None,
annotation_type: AnnotationType::Error,
}),
footer: Vec::new(),
slices: slice.map(|s| vec![s]).unwrap_or_default(),
opt: FormatOptions {
color,
..Default::default()
},
};
DisplayList::from(snippet)
However, if we have a label containing __, then that text gets lost from the label. The reason is that format_label in https://github.com/rust-lang/annotate-snippets-rs/blob/542e41e9a767c1c294564d549c46b2c3974b6481/src/display_list/from_snippet.rs#L56 splits by __ to apply italics to alternate parts of the label. That behaviour was super surprising. I can't find it documented. There seems to be no way to turn it off, and no way to apply escaping to stop it happening. Can you suggest how I might get it so that errors don't get changed as they are rendered?
ha, interesting! Seems like this is my error in https://github.com/rust-lang/annotate-snippets-rs/commit/fe63d9ee72f0e1db154119c6efde15839b674a03
I'm curious no other user encountered it so far!
Can you provide a minimized test to reproduce?
let s = Snippet {
title: Some(Annotation {
label: Some("hello__world"),
id: None,
annotation_type: AnnotationType::Error,
}),
footer: Vec::new(),
slices: Vec::new(),
opt: FormatOptions::default(),
};
eprintln!("{:?}", DisplayList::from(s).to_string());
Prints out "error: helloworld" would I would expect it to print "error: hello__world".
I see! thank you. I don't have time right now to architect a solution to the problem, so marking as helpwanted.
I don't see the reason for parsing __ in the labels at all, so if that's all that's required, I'm happy to send up a patch. More generally, if you can outline the kind of solution you expect, I can either fix it, or find someone who will.
I've added a PR to remove the feature in #54, since the feature was undocumented, and I couldn't figure out what its purpose was. I'd be keen to get something merged, as we use this library in the Rust Starlark library, and it means if a user makes a mistake like typing __foo__ then the error message comes out as merely foo, which is super confusing.