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

fix: function mappings + object naming #2651

Merged
merged 1 commit into from
Nov 7, 2024

Conversation

MartianGreed
Copy link
Contributor

@MartianGreed MartianGreed commented Nov 7, 2024

Description

Closes #2628

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) cc @glihm, I swear this is true
  • 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

    • Updated function generation to include namespaces, enhancing code organization.
    • Added a new method for creating theme functions with camel case naming.
  • Bug Fixes

    • Improved identifier handling to prevent duplication in generated output.
  • Tests

    • Introduced new tests to ensure correct functionality of updated methods and identifier management.

Copy link

coderabbitai bot commented Nov 7, 2024

Walkthrough

Ohayo! This pull request introduces significant modifications to the TsFunctionGenerator struct within the function.rs file. The generate_system_function method's signature has been updated to include a new namespace parameter. Additionally, variable names and keys have been adjusted for consistency, and logic has been implemented to prevent identifier duplication in generated outputs. The changes also include updated tests to validate the new functionality.

Changes

File Path Change Summary
crates/dojo/bindgen/src/plugins/typescript/generator/function.rs - Updated generate_system_function to include namespace: &str.
- Renamed account to snAccount in generate_system_function and format_function_inputs.
- Renamed entryPoint to entrypoint in generated objects.
- Enhanced setup_function_wrapper_end to prevent identifier duplication.
- Added tests for updated methods, including checks for identifier duplication.
- Added method create_change_theme_function_camelized() in the tests module.

Assessment against linked issues

Objective Addressed Explanation
Correct the number of parameters in function calls (issue #2628)
Prevent duplicate identifiers in generated code (issue #2628)
Ensure proper naming conventions for variables (issue #2628)
Include namespace in generated types (issue #2628) Changes do not address all cases of missing namespace.
Fix type conversions for specific fields (issue #2628) Unclear if all necessary type conversions were made.

Possibly related PRs

  • fix: contracts function name clashing #2603: This PR modifies the setup_function_wrapper_end method in TsFunctionGenerator, which is directly related to the changes made in the main PR regarding function name handling and identifier duplication.

Suggested reviewers

  • glihm

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

🧹 Outside diff range and nitpick comments (1)
crates/dojo/bindgen/src/plugins/typescript/generator/function.rs (1)

Line range hint 350-417: The test coverage looks good, but could be even better, sensei!

While the current tests cover the basic duplicate prevention scenarios, consider adding these test cases:

  1. Test with mixed snake_case and camelCase functions in the same contract
  2. Test with namespace variations

Here's a suggested test addition:

#[test]
fn test_mixed_case_functions_with_namespace() {
    let generator = TsFunctionGenerator {};
    let mut buff = Buffer::new();
    
    // Test both cases with different namespaces
    let snake_case_fn = create_change_theme_function();
    let camel_case_fn = create_change_theme_function_camelized();
    
    let contract1 = DojoContract {
        tag: "namespace1-actions".to_owned(),
        tokens: TokenizedAbi::default(),
        systems: vec![],
    };
    
    let contract2 = DojoContract {
        tag: "namespace2-actions".to_owned(),
        tokens: TokenizedAbi::default(),
        systems: vec![],
    };
    
    let _ = generator.generate(&contract1, &snake_case_fn, &mut buff);
    let _ = generator.generate(&contract1, &camel_case_fn, &mut buff);
    let _ = generator.generate(&contract2, &snake_case_fn, &mut buff);
    
    // Assert expected buffer state
    assert_eq!(6, buff.len());  // Should not duplicate functions
    assert!(buff.has("namespace1")); // Should include first namespace
    assert!(buff.has("namespace2")); // Should include second namespace
}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 86365fd and 393aa13.

📒 Files selected for processing (1)
  • crates/dojo/bindgen/src/plugins/typescript/generator/function.rs (10 hunks)
🔇 Additional comments (4)
crates/dojo/bindgen/src/plugins/typescript/generator/function.rs (4)

30-35: Ohayo! The namespace parameter addition looks good, sensei!

This change directly addresses the namespace issue mentioned in #2628, ensuring proper namespace inclusion in provider.execute calls.


67-70: Nice type mapping improvements, sensei!

The additional checks for enum and non-core struct types ensure proper namespace prefixing, which helps prevent type resolution issues in the generated TypeScript code.


182-196: Excellent duplicate prevention logic, sensei!

The added checks effectively prevent function duplication when both snake_case and camelCase versions exist, addressing a key issue from #2628.


40-46: The execute call parameters have been properly aligned, sensei!

The changes address multiple issues from #2628:

  1. Using snAccount prevents duplicate identifier errors
  2. Added namespace parameter ensures proper execution context
  3. Fixed casing of entrypoint for consistency

Let's verify the entrypoint casing consistency across the codebase:

✅ Verification successful

All clear on the entrypoint casing, sensei!

The codebase consistently uses lowercase entrypoint in TypeScript-related code and maintains appropriate casing conventions in other contexts. The changes in the review are correct and align with the TypeScript conventions while not conflicting with other usage patterns:

  • TypeScript/JavaScript files use lowercase entrypoint
  • Rust code appropriately uses snake_case entry_point or PascalCase EntryPoint based on context (types, enums, etc.)
  • Documentation and comments maintain consistent casing within their respective domains
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for any remaining instances of 'entryPoint' that might need updating
rg -i "entryPoint" --type rust

Length of output: 10513

Copy link

codecov bot commented Nov 7, 2024

Codecov Report

Attention: Patch coverage is 95.34884% with 4 lines in your changes missing coverage. Please review.

Project coverage is 57.43%. Comparing base (cf1d99f) to head (393aa13).
Report is 11 commits behind head on main.

Files with missing lines Patch % Lines
...ndgen/src/plugins/typescript/generator/function.rs 95.34% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2651      +/-   ##
==========================================
+ Coverage   56.83%   57.43%   +0.60%     
==========================================
  Files         397      400       +3     
  Lines       49535    49963     +428     
==========================================
+ Hits        28151    28698     +547     
+ Misses      21384    21265     -119     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@glihm glihm merged commit c364d13 into dojoengine:main Nov 7, 2024
14 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.

[BUG] sozo --typescript bindings errors
2 participants