miette
miette copied to clipboard
Multiline support for long labels?
Suppose I'm rendering a type error that involves some large/gnarly types. Ideally, I'd like to format/pretty-print those types over multiple lines to make them readable. But afaict this isn't something supported by miette
at the moment. Any advice? Am I missing something, or are there any plans to support it in future?
miette supports multiline errors. It doesn't differentiate starting and ending positions within lines for those errors, but you should be able to give it a span that crosses line boundaries and get something like this:
https://github.com/zkat/miette/blob/main/tests/graphical.rs#L360-L373
You can even have multiple overlapping spans:
https://github.com/zkat/miette/blob/main/tests/graphical.rs#L492-L505
Did you find a case where this didn't work for you? Happy to assist!
Sorry, I wasn't clear.
I don't mean single errors that span multiple lines in source, I mean more like error labels that are exceedingly long and could benefit from being pretty printed
Something like...
#[derive(Error, Debug, Diagnostic)]
#[error("oops!")]
#[diagnostic(
code(oops::my::bad),
url(docsrs),
help("try doing it better next time?"),
)]
struct MyBad {
#[source_code]
src: NamedSource,
// This label is really long. Currently it will word wrap which is nice.
// But imagine I wanted to insert some newlines myself, e.g. because I'm pretty printing a large type
#[label("Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, ")]
bad_bit: SourceSpan,
}
Does that make sense?
Oh that. Yes it's clear now. I'll update the title to be clearer about it