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

chore: use NodeWithContainer in ResolvedPattern::from_node() + more Binding::list_items() usage #103

Merged

Conversation

arendjr
Copy link
Contributor

@arendjr arendjr commented Mar 28, 2024

With this PR I converted a few more places to use Binding::list_items().

It also became easier to use NodeWithContainer in ResolvedPattern::from_node(), which is a small step towards making sure ResolvedPattern also doesn't depend on Node directly anymore. In a later follow-up NodeWithContainer will probably be swapped for impl AstNode.

Summary by CodeRabbit

  • Refactor
    • Simplified argument passing in various pattern matching implementations, enhancing code clarity and reducing complexity.
    • Improved efficiency in handling list items and bindings within built-in functions and matchers.
    • Streamlined the usage of ResolvedPattern::from_node across multiple modules for more consistent and simplified code.

Copy link
Contributor

coderabbitai bot commented Mar 28, 2024

Walkthrough

The overarching change across these updates focuses on simplifying argument passing and refining method calls within the codebase, particularly around the ResolvedPattern::from_node function. By adopting NodeWithSource as a unified argument, the updates enhance code readability and maintainability, streamlining the handling of pattern matching and function execution across various modules.

Changes

Files Summary
after.rs, before.rs, every.rs, some.rs, within.rs Simplified ResolvedPattern::from_node method calls by changing arguments, enhancing clarity.
ast_node.rs, resolved_pattern.rs Updated ResolvedPattern::from_node to accept NodeWithSource, streamlining parameter passing.
built_in_functions.rs Refactored distinct_fn and shuffle_fn for direct list item processing, reducing code complexity.
contains.rs Improved execute_until function by efficiently handling different types of bindings and importing NodeWithSource.
list.rs Simplified mapping of list items by altering the order of function calls, directly passing ResolvedPattern::from_node and Cow::Owned.

🐰✨
Changes sweep through the land, code refined with a gentle hand.
Arguments passed, so clear and neat,
With NodeWithSource, no feat's too steep.
Across the files, the updates dance,
A rabbit's joy in every glance.
🌟📜✨

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-tests 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 tests 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 tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

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

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link
Contributor

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 7509491 and be5342a.
Files selected for processing (10)
  • crates/core/src/pattern/after.rs (1 hunks)
  • crates/core/src/pattern/ast_node.rs (1 hunks)
  • crates/core/src/pattern/before.rs (1 hunks)
  • crates/core/src/pattern/built_in_functions.rs (2 hunks)
  • crates/core/src/pattern/contains.rs (3 hunks)
  • crates/core/src/pattern/every.rs (1 hunks)
  • crates/core/src/pattern/list.rs (1 hunks)
  • crates/core/src/pattern/resolved_pattern.rs (2 hunks)
  • crates/core/src/pattern/some.rs (1 hunks)
  • crates/core/src/pattern/within.rs (2 hunks)
Additional comments (12)
crates/core/src/pattern/within.rs (1)
  • 91-91: The change to use NodeWithSource::new(n, node.source) for creating a NodeWithSource instance and passing it to ResolvedPattern::from_node is correctly implemented and aligns with the PR objectives to simplify argument passing and improve modularity. Good job on this improvement.
crates/core/src/pattern/after.rs (1)
  • 106-106: The simplification of the argument passed to ResolvedPattern::from_node is correctly implemented, making the code more concise and easier to understand. This aligns well with the PR objectives.
crates/core/src/pattern/before.rs (1)
  • 106-106: The simplification of the input to ResolvedPattern::from_node by removing unnecessary details is correctly implemented, enhancing code readability and maintainability. This aligns well with the PR objectives.
crates/core/src/pattern/every.rs (1)
  • 76-76: The simplification of the argument passed to ResolvedPattern::from_node within a loop is correctly implemented, making the code more concise and easier to understand. This aligns well with the PR objectives.
crates/core/src/pattern/some.rs (1)
  • 77-77: The simplification of the argument passing for pattern resolution in the Some module's Matcher implementation is correctly implemented, enhancing code readability and maintainability. This aligns well with the PR objectives.
crates/core/src/pattern/ast_node.rs (1)
  • 206-206: The update to the argument passed to ResolvedPattern::from_node using NodeWithSource::new(child, source) is correctly implemented, simplifying the code and aligning well with the PR objectives.
crates/core/src/pattern/list.rs (1)
  • 129-130: The simplification of the mapping of list_items to children by directly using ResolvedPattern::from_node and Cow::Owned in the map operations is correctly implemented, making the code more concise and easier to understand. This aligns well with the PR objectives.
crates/core/src/pattern/contains.rs (1)
  • 89-89: The use of NodeWithSource::new(node, src) in the execute_until function is correctly implemented, simplifying the code and making it more modular. This aligns well with the PR objectives.
crates/core/src/pattern/built_in_functions.rs (2)
  • 405-418: The refactoring of distinct_fn to directly handle list items and simplify the logic is a positive change. Ensure the logic correctly identifies and handles unique list items.
  • 449-458: The refactoring of shuffle_fn to directly handle list items and simplify the logic is a positive change. Ensure the logic correctly shuffles the list items.
crates/core/src/pattern/resolved_pattern.rs (2)
  • 20-22: The import of NodeWithSource aligns with the PR objectives, aiming for a cleaner and more modular architecture. Ensure its usage is consistent across the file.
  • 483-484: The modification of the from_node function to accept NodeWithSource instead of separate parameters is a positive change, enhancing modularity. Ensure the logic within the function correctly handles the NodeWithSource type.

Comment on lines +143 to +144
&node.node,
node.source,
Copy link
Contributor

Choose a reason for hiding this comment

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

execute_until could take a node with src instead?

@ilevyor ilevyor merged commit 542cca3 into getgrit:main Mar 28, 2024
4 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