brendanzab / codespan

Beautiful diagnostic reporting for text-based programming languages.
Apache License 2.0
1.1k stars 59 forks source link

move locus calculation to separate function #334

Open Johann150 opened 3 years ago

Johann150 commented 3 years ago

This moves the locus calculation from RichDiagnostic::render to Diagnostic::locuses. Some questions to answer:

Johann150 commented 3 years ago

Please note the CI is failing because of dependencies not being compatible with the oldest tested against Rust version (1.40.0).

brendanzab commented 3 years ago

I'm wondering if there is as way to do this without needing to allocate an intermediate BTreeMap for this? 🤔 That's the one thing that would give me pause I guess.

We might also be able to solve this better if we had some sort of intermediate 'resolved diagnostic' - something I'm hoping we can get to at some stage!

Johann150 commented 3 years ago

The reason for using a BTreeMap was this comment https://github.com/brendanzab/codespan/blob/629d35a4c9f30236a2adbc5773c756d23d1775d7/codespan-reporting/src/term/views.rs#L98-L100 I would not call it an "intermediate BTreeMap" because its used afterwards, like the vector the above comment is referencing.

I don't see a way without allocating some data structure similar to this. We could do with a Vec but that does not come with the deduplication built in, and no advantages that I am aware of.