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: add events in typescript bindgen + sort functions by name #2853

Merged
merged 1 commit into from
Dec 31, 2024

Conversation

MartianGreed
Copy link
Contributor

@MartianGreed MartianGreed commented Dec 31, 2024

Solves #2781 and #2782

Summary by CodeRabbit

  • Refactor
    • Improved TypeScript code generation process for events and contracts
    • Enhanced filtering and sorting of system functions and event composites
    • Simplified logic for extracting and processing contract-related information

Copy link

coderabbitai bot commented Dec 31, 2024

Ohayo, sensei! 🍵 Let's dive into this TypeScript bindgen adventure!

Walkthrough

The pull request modifies the TypeScript code generation process in the Dojo bindgen system. The changes focus on enhancing how events and contracts are processed and transformed into TypeScript code. The TsFileWriter now creates a more structured approach to handling event composites, filtering and sorting them carefully. Similarly, the TsFileContractWriter refines how contract functions are extracted and processed, introducing a more streamlined method for generating TypeScript representations of system functions.

Changes

File Change Summary
crates/dojo/bindgen/src/plugins/typescript/writer.rs - Introduced new event composite collection with filtering and sorting
- Renamed model composites to m_composites
- Updated contract function extraction logic
- Improved error handling for function generation

Suggested Reviewers

  • glihm

Possibly Related PRs

Sensei, the code is ready for your wisdom! 🥷🏼🍱


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 (6)
crates/dojo/bindgen/src/plugins/typescript/writer.rs (6)

25-45: Ohayo sensei, consider extracting event composites into a helper
We see code duplication with the model composites. Extracting common logic for collecting enums, structs, and functions into a standalone helper could reduce redundancy and future maintenance overhead.


Line range hint 47-70: Ohayo sensei, unify repeated pattern for model composites
Similarly, the logic for enumerating model tokens mirrors the event composites. Refactoring to a shared function might keep these expansions in sync and more maintainable.


71-72: Ohayo sensei, nice to see deterministic sorting
Sorting by type_path ensures consistent output. If ties matter or original ordering needs preservation, consider a stable sort.


78-78: Ohayo sensei, watch out for repeated clones
Concatenating cloned vectors is handy but might add overhead for large data sets. Merging them into one vector before iteration could be more efficient.


116-150: Ohayo sensei, handle potential panics gracefully
to_function().unwrap() could panic if conversion fails. While you handle such cases below with a panic!, consider returning an error to propagate gracefully.


157-167: Ohayo sensei, augment error handling
Currently, this loop logs an error if code generation fails and then continues. If partial generation is undesirable, consider failing fast or adding a fallback strategy.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1c3ff08 and 09ef4ae.

📒 Files selected for processing (1)
  • crates/dojo/bindgen/src/plugins/typescript/writer.rs (3 hunks)
🔇 Additional comments (2)
crates/dojo/bindgen/src/plugins/typescript/writer.rs (2)

24-25: Ohayo sensei, new events vector creation looks straightforward
Your approach here to gather event data before processing appears clean and efficient. No immediate issues spotted.


151-151: Ohayo sensei, function sorting looks good
Sorting the contract functions by name is a straightforward way to achieve consistent ordering.

Copy link

codecov bot commented Dec 31, 2024

Codecov Report

Attention: Patch coverage is 15.15152% with 56 lines in your changes missing coverage. Please review.

Project coverage is 56.15%. Comparing base (1c3ff08) to head (09ef4ae).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...ates/dojo/bindgen/src/plugins/typescript/writer.rs 15.15% 56 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2853      +/-   ##
==========================================
- Coverage   56.16%   56.15%   -0.02%     
==========================================
  Files         440      440              
  Lines       56635    56670      +35     
==========================================
+ Hits        31810    31823      +13     
- Misses      24825    24847      +22     

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

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