miette icon indicating copy to clipboard operation
miette copied to clipboard

Feature Request: Support `primary_span` attr

Open bvanjoi opened this issue 1 year ago • 1 comments

Currently, we support the label attribute to display the error source span. However, it seems that an error struct can have multiple labels, which sometimes results in the absence of a primary label. Therefore, I recommend adding a primary_span to indicate the primary span of the diagnostic, ensuring that the main message is clearly associated with a specific location.

The usage should be as follows:

#[derive(Error, Debug, Diag)]
#[error(message)]
struct MyError {
    #[primary_span]
    span: Span
}

bvanjoi avatar Nov 28 '24 04:11 bvanjoi

I wrote about this a couple of years ago but never really made a separate issue for it: https://github.com/zkat/miette/issues/125#issuecomment-1057641548

My main thought about this proposal is I'd rather reuse #[span] and just give it an optional argument to specify whether something is primary. Other than that, I think something like this is long overdue.

zkat avatar Nov 28 '24 07:11 zkat