Skip to content

Conversation

oguzkocer
Copy link
Contributor

This PR introduces a new crate wp_derive, which implements the #[WPContextual] derive macro. This has been a big undertaking, mainly because splitting this PR into multiple parts wasn't a good option. Procedural macro code can be a bit hard to follow unless the reviewer can look up the documentation and tests. Furthermore, we are hoping that we won't need to touch this crate very often - if at all. So, it made sense to make this as production ready as possible.

The best way to learn why we need this macro is to read the documentation which you can generate by running cargo doc. The wp_derive crate level documentation goes through everything in a beginner friendly way whereas the documentation for the #[WPContextual] macro is more technically oriented.

The main test coverage for this implementation uses trybuild which acts as a great documentation in itself, as the errors will be checked into the source control as separate files. With derive macros, it's much more important to have these integration tests than unit tests. Having said that, I felt some of the helper functions were a bit more complicated, so I've added some unit tests for some extra assurance.

The macro has a decent error handling. Since it works with rust-analyzer, developers will get these errors as they type in their editor. The errors show exactly what is causing the issue - at least most of the time. There are some minor instances where the error span is not as good as I'd like, but in those cases I didn't see any practical benefit in introducing any extra complexity.

I've documented the implementation quite a bit, but happy to try and improve that if anything is not clear.

oguzkocer added 30 commits March 6, 2024 17:47
@oguzkocer oguzkocer requested a review from crazytonyli March 28, 2024 18:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants