miette
miette copied to clipboard
adding gettext support
Only string literals are accepted, which is not friendly to gettext.
I'd love to hear more about where this can be improved. I thought most strings could be dynamic by using interpolation, but maybe there's patterns I'm missing? I'm happy to discuss designs and review PRs for this but I don't think I'd do a good job of it on my own.
For instance, in this example, the label message cannot be dynamic.
#[derive(Error, Debug, Diagnostic)]
#[error("oops!")]
#[diagnostic(
code(oops::my::bad),
url(docsrs),
help("try doing it better next time?")
)]
struct MyBad {
// The Source that we're gonna be printing snippets out of.
// This can be a String if you don't have or care about file names.
#[source_code]
src: NamedSource,
// Snippets and highlights can be included in the diagnostic!
#[label("This bit here")]
bad_bit: SourceSpan,
}
When I change it, I get an error complaining that it can only be a string literal.
You should manually implement Diagnostic
in this case I guess?
It would be great if the macro could automatically support LabeledSpan, as demonstrated below:
#[derive(Error, Debug, Diagnostic)]
#[error("oops!")]
#[diagnostic(
code(oops::my::bad),
url(docsrs),
help("try doing it better next time?")
)]
struct MyBad {
// The Source that we're gonna be printing snippets out of.
// This can be a String if you don't have or care about file names.
#[source_code]
src: NamedSource,
// Snippets and highlights can be included in the diagnostic!
#[label]
bad_bit: LabeledSpan, // <- dynamically generated label content
}
would generate something like
impl Diagnostic for RuntimeError {
// ...
fn labels(
&self,
) -> Option<Box<dyn Iterator<Item = miette::LabeledSpan> + '_>> {
// ...
Some(Box::new([self.bad_bit].into_iter())),
// ...
}
// ...
}
This seems feasible. May I take it up?
@abiriadev go for it!