Skip to content
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

Merged
merged 1 commit into from
Jan 14, 2025

Conversation

MartianGreed
Copy link
Contributor

@MartianGreed MartianGreed commented Jan 14, 2025

Description

Related issue

Tests

  • Yes
  • No, because they aren't needed
  • No, because I need help

Added to documentation?

  • README.md
  • Dojo Book
  • No documentation needed

Checklist

  • I've formatted my code (scripts/prettier.sh, scripts/rust_fmt.sh, scripts/cairo_fmt.sh)
  • I've linted my code (scripts/clippy.sh, scripts/docs.sh)
  • I've commented my code
  • I've requested a review after addressing the comments

Summary by CodeRabbit

  • New Features

    • Added support for Cairo unit type representation in TypeScript code generation
    • Improved enum handling and generation in TypeScript bindings
    • Enhanced function generation with more flexible state mutability support
  • Refactor

    • Simplified type checking and default value generation for enums and composites
    • Updated import and function call logic for improved type safety
  • Tests

    • Added new test cases for view functions and system function generation

Copy link

coderabbitai bot commented Jan 14, 2025

Walkthrough

Ohayo, 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

File Change Summary
crates/dojo/bindgen/src/plugins/typescript/generator/constants.rs Added CAIRO_UNIT_TYPE constant with value "()"
crates/dojo/bindgen/src/plugins/typescript/generator/enum.rs - Replaced token_is_custom_enum with token_is_enum
- Simplified enum generation to use export type instead of export enum
- Modified test cases to reflect new type definition structure
crates/dojo/bindgen/src/plugins/typescript/generator/function.rs - Updated import statements
- Modified check_imports to include DojoCall
- Updated build_function_calldata return type
- Added test function for view functions
crates/dojo/bindgen/src/plugins/typescript/generator/mod.rs - Added CAIRO_UNIT_TYPE constant
- Renamed token_is_custom_enum to token_is_enum
- Updated handling of U256 types
- Simplified default value generation for enums and composites

Sequence Diagram

sequenceDiagram
    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
Loading

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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a 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

📥 Commits

Reviewing files that changed from the base of the PR and between fde72d7 and 124d493.

📒 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.

Copy link

codecov bot commented Jan 14, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 55.91%. Comparing base (a5377ac) to head (124d493).
Report is 3 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

@glihm glihm merged commit a295c22 into dojoengine:main Jan 14, 2025
15 checks passed
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