zesterer / ariadne

A fancy diagnostics & error reporting crate
https://crates.io/crates/ariadne
MIT License
1.61k stars 72 forks source link

Expose Source text #100

Closed calder closed 5 months ago

calder commented 5 months ago

Use Case

Please correct if there's a less dumb way of doing this!

I'm using a custom Cache implementation, and would like to maintain a single Id --> Source map. This doesn't work today because there's no way for non-Ariadne consumers like a parser to access Source::text. Exposing it makes Source immediately useful for non-Ariadne applications.

plusvic commented 5 months ago

I was about to open another PR with exactly the same change. I think this extremely useful, if the Source type already owns a copy of the original source code, it would be great if I can access it from my application.

zesterer commented 5 months ago

Thanks for the PR, sorry it took me so long to get round to this.

I'll merge this for now, although I'm somewhat worried about the implications of restricting Source to a contiguous UTF-8 representation internally. I'd rather not make promises about this continuing to exist into the future.