-
Notifications
You must be signed in to change notification settings - Fork 29
[WJ-1168] Add proc macro for generating relation structs and methods #3039
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
emmiegit
wants to merge
104
commits into
develop
Choose a base branch
from
WJ-1168-site-ban-macro
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
104 commits
Select commit
Hold shift + click to select a range
7e2c8d3
Create stub proc macro crate for deepwell.
emmiegit 2aa55b0
Add stub in proc macro subcrate.
emmiegit a3f1cf1
First compiling version of macro crate.
emmiegit 28300fa
Create make_ident() helper.
emmiegit f57d71d
Add dest / from parsing.
emmiegit f2ca29c
Add data type to macro.
emmiegit 97004a2
Fix loop condition.
emmiegit 85263de
Ensure required field and build output.
emmiegit 25309eb
Run rustfmt.
emmiegit dd6f13a
Add lines between each argument.
emmiegit 4f0829f
Error if field is set multiple times.
emmiegit 1cad13c
Add process_type for handling () -> null.
emmiegit bfc022e
Add data_type and method arguments.
emmiegit 829fc40
Remove root TODO.
emmiegit 4147596
Bump macro crate version to 0.0.2
emmiegit e01897f
Add define_struct argument to macro.
emmiegit 9924ddd
Suppress some warnings.
emmiegit 2b50ac5
Bump macro crate version to 0.0.3
emmiegit 0155c8c
Set up testing.
emmiegit b41aec5
Intake commas after each key and value.
emmiegit 6fec51d
Perform lookahead in GenerateMethod::parse().
emmiegit 589b2c4
Set up first unit test for settings parsing.
emmiegit 011ec4f
Add another unit test case.
emmiegit 4f58fcf
Bump macro crate version to 0.0.4
emmiegit db48c46
Add remaining parse unit test cases.
emmiegit f9cab9b
Remove generation unit test.
emmiegit 74572ff
Bump macro crate version to 0.0.5
emmiegit 255a1c5
Add new assert_type() helper function.
emmiegit db87738
Remove GenerateMethod, replace with boolean.
emmiegit ea3f695
Store names as String, not Ident.
emmiegit 1bac0fc
Bump macro crate version to 0.0.6
emmiegit dd5780b
Add initial expansion code.
emmiegit 395f6d1
Bump macro crate version to v0.0.7
emmiegit 97d8047
Move get methods to separate function.
emmiegit b9fba4e
Move create and remove sections to helper functions.
emmiegit 1af698a
Get generation parts in main function.
emmiegit 40e9a3d
Remove metadata field in definition if null.
emmiegit 8b57275
Generate code at top level.
emmiegit d92aeb8
Bump macro crate version to 0.0.8
emmiegit c85ad21
Remove define_struct argument.
emmiegit 36dd7eb
Add visibility / naming for remove method.
emmiegit 977410c
Remove integration test stub for macro crate.
emmiegit 1e51e15
Bump macro crate version to 0.0.9
emmiegit 9c647d8
Allow disabling struct/method generation entirely.
emmiegit 5314985
Bump macro macro crate version to 0.0.10
emmiegit 7ea0bb4
Rename enum cases.
emmiegit eba82e7
Use assert_type() for data_type too.
emmiegit 4dbf8ed
Rename GenerateMethod enum cases.
emmiegit 59a4465
Use ? for unwrapping Option from vis_and_suffix().
emmiegit c92f625
Address remaining clippy lint.
emmiegit 073a7fa
Bump macro crate version to 0.0.11
emmiegit 5a7b406
Add new procedural macro crate.
emmiegit da68494
Generate get structs.
emmiegit bb57dc1
Bump macro crate version to 0.0.12
emmiegit cea9d06
Add RelationType enum as type representation.
emmiegit 79fc8ca
Bump macro crate version to 0.0.13
emmiegit 37850b3
Rename RelationType -> RelationObjectType.
emmiegit 46c26ed
Fix RelationType output.
emmiegit bb324fd
Bump macro crate version to 0.1.0
emmiegit 545d2ec
Properly add type path to token output.
emmiegit fec5573
Bump macro crate version to 0.1.1
emmiegit 5c9c36e
Fix types for dest / from in 'Get' struct.
emmiegit 916467f
Ensure generation of RelationObjectType as tokens is the variant path.
emmiegit 90ca9c1
Bump crate version to 0.1.2
emmiegit aebbaec
Pass in empty data to create() method.
emmiegit 2eaf6e8
Add missing argument to get() method.
emmiegit b7e88c0
Bump macro crate version to 0.1.3
emmiegit 6397ab6
Add basic README to explain proc macro crate.
emmiegit a3a8ad2
Bump macro crate version to 0.1.4
emmiegit b4dac19
Replace first relation generation (PageStar) with new proc macro.
emmiegit 34ad091
Replace PageWatch relation with new macro.
emmiegit 72fa13f
Add "inner" struct with borrowed data.
emmiegit c830566
Replace SiteBan relation with new macro.
emmiegit f63aa04
Replace SiteMember relation with new macro.
emmiegit 58a80de
Add manual remove method to SiteMember relation.
emmiegit e07e49f
Add AuditEvent variants for site membership.
emmiegit 0f388fb
Add audit logging for site membership relation events.
emmiegit 8406d0a
Make enriched create / remove struct use consistent.
emmiegit 9f9e0f8
Remove remove_site_ban_with_audit() method with new macro.
emmiegit 39d153e
Add reason to site membership revokes.
emmiegit 0fa2f8d
Bump macro crate version to 0.1.5
emmiegit 63284c4
Create constant for SYSTEM_IP_ADDRESS.
emmiegit 12d34f7
Replace SiteUser relation with new macro.
emmiegit 738b4c2
Replace UserBlock relation with new macro.
emmiegit 9c79dc2
Replace UserFollow relation with new macro.
emmiegit 1f60ba4
Convert UserBotOwner relation to new macro.
emmiegit 31a4d26
Add rustdocs for proc macro.
emmiegit efd7aba
Link this PR in the proc macro README.
emmiegit 1444e1d
Add proc macro testing to CI.
emmiegit 7b170ff
Forbid unsafe code in proc macro.
emmiegit 353386e
Bump macro crate version to 1.0.0
emmiegit 815c530
Remove old relation codegen macro.
emmiegit 747febf
Fix integration tests.
emmiegit 9f0d05f
Move latest_audit_event() to new helper module.
emmiegit d57b1b2
Handle unused helper function warnings.
emmiegit fbf5fb4
Add assertions for site_member.join event.
emmiegit e8240d7
Add assertions for site_member.remove event.
emmiegit c62ec93
Add PrivateWithStruct variant to proc macro.
emmiegit eabb6e7
Add GenerateMethodSettings to enable Private vs PrivateWithStruct.
emmiegit 40a8bde
Update tests with new variants.
emmiegit 81cd352
Change to identifier-based GenerateMethod values.
emmiegit d54d238
Bump macro crate version to 1.1.0
emmiegit af88cd4
Convert to new GenerateMethod specifiers.
emmiegit c2be791
Bump deepwell version to v2026.7.27
emmiegit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| [package] | ||
| name = "deepwell-relation-impl-derive" | ||
| description = "Procedural macro to generate boilerplate for relation methods" | ||
| repository = "https://github.com/scpwiki/wikijump/tree/develop/deepwell/relation-impl-derive" | ||
|
|
||
| version = "1.1.0" | ||
| authors = ["Emmie Smith <emmie.maeda@gmail.com>"] | ||
| edition = "2024" | ||
|
|
||
| [lib] | ||
| proc-macro = true | ||
|
|
||
| [dependencies] | ||
| syn = "3" | ||
| quote = "1" | ||
| proc-macro2 = "1" | ||
|
|
||
| [lints.rust] | ||
| unsafe_code = "forbid" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # deepwell-relation-impl-derive | ||
|
|
||
| This helper crate exists to store the procedural macro for generating methods and structures for relations (see `RelationService`). The [old `impl_relation!` macro](https://github.com/scpwiki/wikijump/blob/0a26522e50e0a2bdc0abddfe6338e6a882d24b74/deepwell/src/services/relation/macros.rs#L23) was defined via `macro_rules!`, but as it grew more complicated and took more options, it became increasingly cumbersome to maintain. | ||
|
|
||
| This proc macro performs the same tasks as the old macro, but with better syntax, more options, and avoiding automatable work (e.g. converting between `PascalCase` and `snake_case`). | ||
|
|
||
| See #3039 for further information. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| //! Helper utilities in processing different naming cases. | ||
|
|
||
| /// Convert `PascalCase` to `snake_case`. | ||
| pub fn pascal_to_snake_case(value: &str) -> String { | ||
| let mut output = String::new(); | ||
| for (i, ch) in value.char_indices() { | ||
| if i > 0 && ch.is_uppercase() { | ||
| output.push('_'); | ||
| } | ||
| output.push(ch.to_ascii_lowercase()); | ||
| } | ||
| output | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_pascal_to_snake_case() { | ||
| macro_rules! test { | ||
| ($pascal_case:expr, $snake_case:expr $(,)?) => {{ | ||
| let actual_snake_case = pascal_to_snake_case($pascal_case); | ||
| let expected_snake_case = $snake_case; | ||
| assert_eq!( | ||
| actual_snake_case, expected_snake_case, | ||
| "actual snake_case conversion doesn't match expected", | ||
| ); | ||
| }}; | ||
| } | ||
|
|
||
| test!("", ""); | ||
| test!("Foo", "foo"); | ||
| test!("FooBar", "foo_bar"); | ||
| test!( | ||
| "AVeryLongNameWithManyParts", | ||
| "a_very_long_name_with_many_parts", | ||
| ); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.