@zbraniecki created https://github.com/zbraniecki/annotate-snippets-rs which basically does Rust-style formatting of code snippets for errors, to be used within Fluent.
I think we should try and move our snippet code out of tree, preferably merging it with annotate-snippets-rs (which is already close to what rustc does), so that it's reusable.
@zbraniecki has agreed to make whatever changes necessary to the crate to make it usable within rustc.
cc @estebank
cc @rust-lang/wg-diagnostics
We just had our first wg-diagnostics meeting and think that a good first step would be to create a new (unstable) diagnostics renderer (we have json, short and human right now). Basically it would use the existing diagnostics backend to call into annotate-snippets.
We can then create a way to run ui tests with the new backend and see how the output changes and circle back to changing annotate-snippets until we are happy.
And once we are all happy, we can get rid of the old human emitter and replace it with the new annotate-snippets based one.
@zbraniecki in order to be able to use this in rustc, we'd need to move your crate into the rust-lang organization and give publish rights to some compiler devs so that we have quick access to it if anything needs doing. Are you ok with that?
Yes! I'd love to hand it over to the Rust team and would be happy to see contributions or hand over to new maintainer if that's better for you! I will continue using it for fluent-rs, but I feel like the crate supports all my direct needs while it will need more features for Rust I believe (since Rust errors are more complex!)
@zbraniecki if you give me admin access to the repo I can migrate it.
Invited!
I can push but I can't move. Hmm.
Maybe transfer the repo to me and then I can transfer it to rust-lang?
I tried to transfer to you
If no one else has picked this up yet, I'd be interested in working on this. I'm currently working on adding the new diagnostics error-format.
I'm happy to help you brainstorm, or review or whatever is needed. :)
I figured I'd post a small status update as it has been a while since the last changes.
We currently have the AnnotateSnippetEmitterWriter that emits
basic diagnostics using the annotate-snippet library. This writer is
essentially taking rustc's Diagnostic and turns that into an
annotate-snippet::Snippet. Currently this doesn't include suggestions
(#61809) and that's the thing I've been working on and off, with some
help from @zbraniecki.
The main problem with turning rustc annotations into annotate-snippet
annotations is that rustc annotation spans are line-based (using
FileWithAnnotatedLines), whereas annotate-snippet
expects the annotation spans to be relative to the start of the provided
snippet.
There's currently two open WIP PRs for annotate-snippet that would make it
possible to provide line-based annotations. It would be great to make some
progress there as that means we won't have to convert from line-relative to
snippet-relative annotation spans in our emitter.
Once annotation support has landed for the new emitter it would be a good time
to see where the output differs the most and what the next steps are.
Most helpful comment
Done! https://github.com/rust-lang/annotate-snippets-rs