Skip to content
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

__ gets lost from labels #53

Closed
ndmitchell opened this issue Nov 24, 2021 · 5 comments
Closed

__ gets lost from labels #53

ndmitchell opened this issue Nov 24, 2021 · 5 comments
Labels
E-help-wanted Call for participation: Help is requested to fix this issue

Comments

@ndmitchell
Copy link
Contributor

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

for (idx, element) in label.split("__").enumerate() {
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?

@zbraniecki
Copy link
Contributor

ha, interesting! Seems like this is my error in fe63d9e

I'm curious no other user encountered it so far!

Can you provide a minimized test to reproduce?

@ndmitchell
Copy link
Contributor Author

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".

@zbraniecki zbraniecki added the E-help-wanted Call for participation: Help is requested to fix this issue label Nov 30, 2021
@zbraniecki
Copy link
Contributor

I see! thank you. I don't have time right now to architect a solution to the problem, so marking as helpwanted.

@ndmitchell
Copy link
Contributor Author

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.

@ndmitchell
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-help-wanted Call for participation: Help is requested to fix this issue
Projects
None yet
Development

No branches or pull requests

2 participants