-
Notifications
You must be signed in to change notification settings - Fork 188
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
feat: change enum to CairoCustomEnum #2907
Conversation
WalkthroughOhayo, sensei! The pull request introduces changes across several Rust files in the Dojo bindgen TypeScript generator. The modifications focus on enhancing enum handling, function generation, and type representation. A new constant for the Cairo unit type has been added, and the enum generation logic has been simplified to use type definitions instead of traditional enum declarations. The changes also include updates to function generation and default value handling for various types. Changes
Sequence DiagramsequenceDiagram
participant Generator as TypeScript Generator
participant Enum as Enum Handler
participant Function as Function Generator
Generator->>Enum: Generate Enum Representation
Enum-->>Generator: Create Type Definition
Generator->>Function: Process Function Signature
Function->>Function: Check Imports
Function-->>Generator: Generate Function Call
The sequence diagram illustrates the high-level flow of the TypeScript generator, showing how enum and function representations are processed and generated. The changes introduce a more streamlined approach to handling different type representations and function calls. Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
crates/dojo/bindgen/src/plugins/typescript/generator/enum.rs (1)
32-50
: Enhanced enum type generation format.The generate method now produces a more TypeScript-friendly output with type definitions and CairoCustomEnum integration.
Consider adding JSDoc comments to document the generated types for better developer experience.
crates/dojo/bindgen/src/plugins/typescript/generator/mod.rs (1)
Line range hint
293-309
: Improved struct default value generation.The build_struct_default_value function now generates cleaner output without unnecessary field order information.
Consider adding type validation to ensure the generated default values match the expected types.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
crates/dojo/bindgen/src/plugins/typescript/generator/constants.rs
(1 hunks)crates/dojo/bindgen/src/plugins/typescript/generator/enum.rs
(5 hunks)crates/dojo/bindgen/src/plugins/typescript/generator/function.rs
(9 hunks)crates/dojo/bindgen/src/plugins/typescript/generator/mod.rs
(15 hunks)
🔇 Additional comments (7)
crates/dojo/bindgen/src/plugins/typescript/generator/constants.rs (1)
14-14
: Ohayo sensei! LGTM - Unit type constant added.The addition of
CAIRO_UNIT_TYPE
constant follows the established pattern and will be useful for handling Cairo's unit type.crates/dojo/bindgen/src/plugins/typescript/generator/enum.rs (1)
Line range hint
15-22
: Ohayo! Simplified enum type checking logic.The check_import method now uses the simplified token_is_enum function, making the code more maintainable.
crates/dojo/bindgen/src/plugins/typescript/generator/function.rs (3)
14-18
: Updated provider imports for better type safety.The import statement now includes DojoCall, improving type safety in function generation.
95-95
: Simplified view function call pattern.The provider.call usage has been streamlined for view functions.
332-364
: Added comprehensive view function test coverage.Good addition of test cases for view functions, ensuring proper behavior.
crates/dojo/bindgen/src/plugins/typescript/generator/mod.rs (2)
54-56
: Simplified enum type checking.The token_is_enum function now has a clearer, more focused responsibility.
77-77
: Added unit type support.Proper handling of Cairo's unit type in type conversion.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2907 +/- ##
==========================================
+ Coverage 55.84% 55.91% +0.06%
==========================================
Files 449 449
Lines 57730 57860 +130
==========================================
+ Hits 32242 32350 +108
- Misses 25488 25510 +22 ☔ View full report in Codecov by Sentry. |
Description
Related issue
Tests
Added to documentation?
Checklist
scripts/prettier.sh
,scripts/rust_fmt.sh
,scripts/cairo_fmt.sh
)scripts/clippy.sh
,scripts/docs.sh
)Summary by CodeRabbit
New Features
Refactor
Tests