locations: Add support for Spans with exact location of AST nodes
@jakeswenson initially suggested this PR in https://github.com/apache/datafusion-sqlparser-rs/pull/839. We are using it in SYNQ to drive our code-column lineage experience. I rebased it on the latest main.
After I rebased it to suggest this change, I noticed an ongoing effort in https://github.com/apache/datafusion-sqlparser-rs/pull/1435.
If you consider the design suggested here for inclusion, I plan to add tests. We have an extensive internal test suite living in a downstream project using a fork of this library.
In our case, the accuracy of code locations is critical since we use it to drive the whole navigation experience. I like the WithSpan<T> approach better, as I know what element and where has accurate locations. In our original codebase not all Indents are wrapped in WithSpan but since this rebase effort was not a small thing I decided to replace all Ident with WithSpan<Ident>. Also to reduce future conflicts/PRs to add more locations.
TODO:
- [ ] Add tests ensuring accurate location capture.
- [ ] Remove
empty_span()from parser. We didn't have some new nodes/quirks on our older fork. - [ ] Add additional
WithSpan<T>where it makes sense, e.g. aroundExpr