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(sozo): adjust typescript bindgen to v1 #2202

Merged
merged 13 commits into from
Jul 25, 2024
Merged

fix(sozo): adjust typescript bindgen to v1 #2202

merged 13 commits into from
Jul 25, 2024

Conversation

ponderingdemocritus
Copy link
Contributor

@ponderingdemocritus ponderingdemocritus commented Jul 22, 2024

  • improves typescript bindgen v1

Summary by CodeRabbit

  • New Features

    • Enhanced TypeScript plugin functionality with refined formatting and processing of enums and contract components.
    • Introduced a new helper function for deriving namespaces from contract tags.
    • Added support for asynchronous programming with the inclusion of the tokio dependency.
  • Improvements

    • Implemented filtering mechanisms to exclude specific tokens and systems during processing, improving output precision.
    • Updated the cainome dependency to a newer version for bug fixes and enhancements.
    • Revised dependency management practices for better readability and maintenance.
  • Tests

    • Introduced comprehensive tests for the TypeScript plugin to validate code generation, type mapping, contract name formatting, and namespace extraction.
    • Added tests to ensure new functionalities are properly validated and output meets expectations.

Copy link

coderabbitai bot commented Jul 22, 2024

Walkthrough

Ohayo, sensei! The recent updates to the TypescriptPlugin significantly enhance its functionality by introducing refined filtering mechanisms that allow it to skip specific tokens and systems. This streamlining improves the formatting of enums and contract components, while a new helper function aids in namespace extraction for efficient output generation. Additionally, the Cargo.toml has been updated to utilize newer dependency versions, ensuring stability and clarity in project management.

Changes

Files Change Summary
crates/dojo-bindgen/src/plugins/typescript/mod.rs - Updated format_system to include a namespace parameter, filtering out specific system names.
- Modified format_enum to skip certain Option types during formatting.
- Enhanced defineContractComponents with filtering for excluded tokens.
- Added get_namespace_from_tag function for namespace extraction.
crates/dojo-bindgen/Cargo.toml - Updated cainome dependency from tag v0.3.0 to v0.3.2 for bug fixes and enhancements.
- Reformatted alloy-provider features list for improved readability.
- Added assert_matches and tokio dependencies to the workspace configuration, enhancing testing and asynchronous functionality.
crates/dojo-bindgen/src/plugins/typescript/tests.rs - Introduced comprehensive tests for the TypescriptPlugin, validating code generation, type mapping, contract name formatting, namespace extraction, and model formatting.

Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2d04f58 and 05c75cf.

Files selected for processing (1)
  • crates/dojo-bindgen/Cargo.toml (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • crates/dojo-bindgen/Cargo.toml

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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, codebase verification and nitpick comments (1)
crates/dojo-bindgen/src/plugins/typescript/mod.rs (1)

326-339: Ohayo, sensei!

The recent changes to the format_system function in typescript/mod.rs include an additional namespace parameter, which is a great improvement. However, the function calls in unity/mod.rs and typescript_v2/mod.rs still use the old signature and need to be updated.

Please update the following locations to include the namespace parameter:

  • crates/dojo-bindgen/src/plugins/unity/mod.rs

    • Line: fn format_system(system: &Function, handled_tokens: &HashMap<String, Composite>) -> String
    • Line: .map(|system| UnityPlugin::format_system(system.to_function().unwrap(), handled_tokens))
  • crates/dojo-bindgen/src/plugins/typescript_v2/mod.rs

    • Line: fn format_system(system: &Function, handled_tokens: &[Composite]) -> String
    • Line: .map(|system| TypeScriptV2Plugin::format_system(system.to_function().unwrap(), handled_tokens))

This will ensure all function calls are consistent with the new signature.

Analysis chain

Ohayo, sensei! The addition of the namespace parameter and filtering mechanism is a great improvement.

This change enhances the control flow by skipping specific systems during processing.

However, ensure that all function calls to format_system match the new signature.


Ohayo, sensei!

The recent changes to the format_system function in typescript/mod.rs include an additional namespace parameter, which is a great improvement. However, it appears that other files (unity/mod.rs and typescript_v2/mod.rs) still use the old signature.

Let's ensure all calls to format_system match the new signature. Here's a follow-up script to locate all calls to format_system and verify their signatures:

Once we have this information, we can pinpoint the exact locations that need updating.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `format_system` match the new signature.

# Test: Search for the function usage. Expect: Only occurances of the new signature.
rg --type rust -A 5 $'format_system'

Length of output: 3178


Script:

#!/bin/bash
# Description: Verify all function calls to `format_system` match the new signature.

# Search for all calls to `format_system` and display context lines to check their signatures.
rg --type rust 'format_system' -A 3 -B 3

Length of output: 4166

Copy link

codecov bot commented Jul 22, 2024

Codecov Report

Attention: Patch coverage is 0% with 100 lines in your changes missing coverage. Please review.

Project coverage is 68.06%. Comparing base (8a1a652) to head (fe5731e).
Report is 1 commits behind head on main.

Files Patch % Lines
crates/dojo-bindgen/src/plugins/typescript/mod.rs 0.00% 100 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2202      +/-   ##
==========================================
- Coverage   68.17%   68.06%   -0.11%     
==========================================
  Files         336      336              
  Lines       44053    44122      +69     
==========================================
+ Hits        30032    30033       +1     
- Misses      14021    14089      +68     

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

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

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

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

Comment on lines +142 to +152
// filter out common types
// TODO: Make cleaner
if token.type_path == "core::option::Option::<core::integer::u32>"
|| token.type_path == "core::option::Option::<core::integer::u8>"
|| token.type_path == "core::option::Option::<core::integer::u16>"
|| token.type_path == "core::option::Option::<core::integer::u64>"
|| token.type_path == "core::option::Option::<core::integer::u128>"
|| token.type_path == "core::option::Option::<core::integer::u256>"
{
return String::new(); // Return an empty string for these enums
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohayo sensei! Optimize the filtering mechanism for enums.

Consider using a set for cleaner and more efficient filtering of Option types.

let excluded_types: HashSet<&str> = [
    "core::option::Option::<core::integer::u32>",
    "core::option::Option::<core::integer::u8>",
    "core::option::Option::<core::integer::u16>",
    "core::option::Option::<core::integer::u64>",
    "core::option::Option::<core::integer::u128>",
    "core::option::Option::<core::integer::u256>",
].iter().cloned().collect();

if excluded_types.contains(token.type_path.as_str()) {
    return String::new(); // Return an empty string for these enums
}

Comment on lines +346 to +359
fn format_system(system: &Function, handled_tokens: &[Composite], namespace: String) -> String {
if [
"contract_name",
"namespace",
"tag",
"name_hash",
"selector",
"dojo_init",
"namespace_hash",
]
.contains(&system.name.as_str())
{
return String::new();
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohayo sensei! Optimize the filtering mechanism for systems.

Consider using a set for cleaner and more efficient filtering of system names.

let excluded_systems: HashSet<&str> = [
    "contract_name",
    "namespace",
    "tag",
    "name_hash",
    "selector",
    "dojo_init",
    "namespace_hash",
].iter().cloned().collect();

if excluded_systems.contains(system.name.as_str()) {
    return String::new();
}

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, codebase verification and nitpick comments (3)
crates/dojo-bindgen/src/plugins/typescript/mod.rs (3)

142-152: Ohayo sensei! Optimize the filtering mechanism for enums.

Consider using a set for cleaner and more efficient filtering of Option types.

let excluded_types: HashSet<&str> = [
    "core::option::Option::<core::integer::u32>",
    "core::option::Option::<core::integer::u8>",
    "core::option::Option::<core::integer::u16>",
    "core::option::Option::<core::integer::u64>",
    "core::option::Option::<core::integer::u128>",
    "core::option::Option::<core::integer::u256>",
].iter().cloned().collect();

if excluded_types.contains(token.type_path.as_str()) {
    return String::new(); // Return an empty string for these enums
}

206-231: Ohayo sensei! Improve readability of field mapping.

Consider breaking down the field mapping logic into smaller helper functions for better readability and maintainability.


346-359: Ohayo sensei! Optimize the filtering mechanism for systems.

Consider using a set for cleaner and more efficient filtering of system names.

let excluded_systems: HashSet<&str> = [
    "contract_name",
    "namespace",
    "tag",
    "name_hash",
    "selector",
    "dojo_init",
    "namespace_hash",
].iter().cloned().collect();

if excluded_systems.contains(system.name.as_str()) {
    return String::new();
}

@glihm glihm changed the title Loaf bindgen fix(sozo): adjust typescript bindgen to v1 Jul 25, 2024
Copy link
Collaborator

@glihm glihm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ponderingdemocritus goes rusty!

@glihm glihm merged commit 1da9fff into main Jul 25, 2024
11 checks passed
@glihm glihm deleted the loaf-bindgen branch July 25, 2024 04:12
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