-
-
Notifications
You must be signed in to change notification settings - Fork 262
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
Conditionally implement miette::Diagnostic
for pest::error:Error
#663
Conversation
The standard workaround for this would be a |
Sure, but what would the |
Personally, I don't think a non-exposed For comparison, this is also the pattern used by |
#[error("Failure to parse at {}", self.0.line_col)] | ||
pub(crate) struct MietteAdapter<R: RuleType>(pub(crate) Error<R>); | ||
|
||
impl<R: RuleType> Diagnostic for MietteAdapter<R> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
errors could also contain path
and continued_line
-- should those also be included in a Diagnostic
(e.g. as additional labels) or would including those make the Miette default formatted print outs look strange?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it would make the miette-fornatted output strange. Adding it to the Display is fine, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, there's a way around it, but it's a bit hacky:
Provide a custom impl SourceCode
which reattaches the line to the span offset information, and then the LabeledSpan
can carry the correct span. If the label span is outside SourceCode
, weird things can happen (mostly just dropping the source pointer, hopefully).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd want to see a snapshot-style test that shows one or more instances of the miette-formatted error before merging this.
(This could be as simple as assert_eq!(format!("{it:?}"), "expected")
or as complex as (waiting for) #661 and using insta or expect_test.)
That said, it's about time to pass the buck on pressing the green button, so...
(apparently I forgot to push the button to unassign the team when it chooses a load-balanced member) @pest-parser/maintainers should have write/merge permissions 🎉 |
Great! (blocked by #666) |
Have you considered reopening this? I'm interested in working on this. |
@prsabahrami sure, feel free to go ahead. Do you want to start with the snapshot tests for the errors? |
@prsabahrami or it's also fine if you start directly with this PR and just add a simple test or two with |
Hides an implementation of miette's
Diagnostic
type under themiette
feature flag. Also adds example usage to theparens
example.The only issue I have with this is that the Display of
error::Error
changes based on this flag. Since miette displays the error and then the diagnostic, the error would be printed twice: once in pest's form, and once in miette's form. Hnce,error.rs:32-33
changes the display value ofError
if the miette feature is enabled. In my opinion, it's not a clean solution, so I'd love to hear feedback.Note: public API change:
pest::error::Error::formt(&self) -> String
is publicized, so users on the miette feature flag can still read Pest's errors if needed.Closes #582