Skip to content

✨ Rust #58

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

Merged
merged 3 commits into from
Apr 5, 2025
Merged

✨ Rust #58

merged 3 commits into from
Apr 5, 2025

Conversation

NatoBoram
Copy link
Collaborator

@NatoBoram NatoBoram commented Apr 3, 2025

Summary by CodeRabbit

  • New Features

    • Introduced Rust language support with dynamic registration and parsing capabilities.
    • Enabled automated post-installation tasks and configured dependencies for a streamlined setup.
  • Documentation

    • Added a comprehensive README detailing installation commands and usage examples.
  • Tests

    • Implemented a testing environment to validate accurate Rust code parsing and syntax tree identification.

Copy link

coderabbitai bot commented Apr 3, 2025

Warning

Rate limit exceeded

@NatoBoram has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 12 minutes and 57 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 39fe1bc and 4bb8d70.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (7)
  • .changeset/nice-eagles-search.md (1 hunks)
  • packages/rust/README.md (1 hunks)
  • packages/rust/index.d.ts (1 hunks)
  • packages/rust/index.js (1 hunks)
  • packages/rust/nursery.js (1 hunks)
  • packages/rust/package.json (1 hunks)
  • packages/rust/postinstall.js (1 hunks)

Walkthrough

This pull request introduces a new Rust language package for ast-grep. It adds comprehensive documentation with installation and usage instructions, along with type definitions and JavaScript exports that register the Rust language. Additionally, it includes a testing setup using the nursery package, a post-installation script for language setup, and package metadata required for proper publishing.

Changes

File(s) Change Summary
.../rust/README.md Added a README with installation commands and usage examples for the Rust NAPI language package.
.../rust/index.d.ts, .../rust/index.js Introduced a new LanguageRegistration type and a registration constant/object with properties such as libraryPath, extensions, languageSymbol, and expandoChar for registering Rust.
.../rust/package.json Added package metadata including dependencies, scripts, and publish configuration for @ast-grep/lang-rust.
.../rust/nursery.js, .../rust/postinstall.js Added a testing setup using @ast-grep/nursery and a post-install script that utilizes @ast-grep/setup-lang to perform necessary configuration.

Sequence Diagram(s)

sequenceDiagram
    participant Dev as Developer
    participant Reg as Rust Language Module
    participant Parser as Rust Parser
    participant Tester as Nursery Test Runner

    Dev->>Reg: Import module & register language
    Reg->>Parser: Load shared object (parser.so)
    Parser-->>Reg: Return parsing capabilities
    Dev->>Tester: Run test setup with nursery
    Tester->>Parser: Parse sample Rust code
    Parser-->>Tester: Return AST (e.g., call_expression)
Loading

Possibly related PRs

  • feat: add tree-sitter-c #35: Introduced the LanguageRegistration type and registration constant for the C language, establishing a pattern mirrored in this Rust package.
  • feat: C# language #41: Added a new language package (@ast-grep/lang-csharp) with similar type definitions, exports, and setup files, aligning closely with the changes in the Rust implementation.

Suggested reviewers

  • HerringtonDarkholme

Poem

I'm a bunny hopping in code so bright,
Parsing Rust with all my might.
Each line and test makes my ears stand high,
In fields of logic, I softly fly.
CodeRabbit cheers as new changes come to light!
🐰✨


🪧 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.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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.

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

🧹 Nitpick comments (4)
packages/rust/README.md (1)

3-12: Installation instructions are helpful but could be more flexible.

The installation instructions are clear and include all necessary dependencies. However, they only mention pnpm without alternatives for users who might use npm or yarn.

Consider adding installation instructions for npm and yarn users as well:

 # ast-grep napi language for rust
 
 ## Installation
 
-In a pnpm project, run:
+Install using your preferred package manager:
 
+### pnpm
 ```bash
 pnpm install @ast-grep/lang-rust
 pnpm install @ast-grep/napi
 # install the tree-sitter-cli if no prebuild is available
 pnpm install @tree-sitter/cli --save-dev

+### npm
+bash +npm install @ast-grep/lang-rust +npm install @ast-grep/napi +# install the tree-sitter-cli if no prebuild is available +npm install @tree-sitter/cli --save-dev +
+
+### yarn
+bash +yarn add @ast-grep/lang-rust +yarn add @ast-grep/napi +# install the tree-sitter-cli if no prebuild is available +yarn add @tree-sitter/cli --dev +

packages/rust/nursery.js (1)

5-16: Test setup is well-structured but could use more comprehensive tests.

The test setup correctly configures the Rust language and includes a basic test that verifies parsing a simple Rust function with a Some(123) expression. While this is a good start, more complex syntax testing would be beneficial.

Consider expanding the test coverage to include more Rust-specific syntax features like:

  • Traits and implementations
  • Match expressions
  • Lifetimes and generics
  • Macros
  • Async/await syntax

Example of a more comprehensive test:

testRunner: parse => {
  // Basic function test
  const sg1 = parse('fn test() { Some(123) }')
  const root1 = sg1.root()
  const node1 = root1.find('Some($A)')
  assert.equal(node1.kind(), 'call_expression')
  
  // Test trait implementation
  const sg2 = parse('impl Display for Point { fn fmt(&self, f: &mut Formatter) -> Result { write!(f, "({}, {})", self.x, self.y) } }')
  const root2 = sg2.root()
  const node2 = root2.find('write!($A, $B, $C, $D)')
  assert.equal(node2.kind(), 'macro_invocation')
  
  // Test match expression
  const sg3 = parse('match x { Some(n) => println!("{}", n), None => {} }')
  const root3 = sg3.root()
  const node3 = root3.find('Some($A)')
  assert.equal(node3.kind(), 'call_expression')
}
packages/rust/package.json (2)

4-4: Add a descriptive package description.

The description field is currently empty. Add a concise description like "Rust language support for ast-grep" to help users understand the package's purpose.


22-22: Add author information.

The author field is currently empty. Consider adding author information for proper attribution.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 002639c and 39fe1bc.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (6)
  • packages/rust/README.md (1 hunks)
  • packages/rust/index.d.ts (1 hunks)
  • packages/rust/index.js (1 hunks)
  • packages/rust/nursery.js (1 hunks)
  • packages/rust/package.json (1 hunks)
  • packages/rust/postinstall.js (1 hunks)
🔇 Additional comments (16)
packages/rust/postinstall.js (1)

1-4: Clean and appropriate implementation for post-installation setup.

The implementation correctly imports and uses the postinstall function from the @ast-grep/setup-lang package, passing the current directory. This approach is consistent with other language packages in the ast-grep ecosystem.

packages/rust/index.d.ts (2)

1-7: Well-structured type definition for language registration.

The LanguageRegistration type properly defines the expected properties for registering a language with ast-grep. The optional fields are correctly marked with the ? operator.


9-10: Export declaration looks good.

The constant declaration and default export follow TypeScript best practices.

packages/rust/README.md (2)

1-2: Clear and concise title.

The title accurately describes the package's purpose.


14-24: Usage example is clear and effective.

The code example clearly demonstrates how to use the Rust language with ast-grep. It shows the key steps: importing the language, registering it, and parsing code.

packages/rust/nursery.js (1)

1-4: Appropriate imports and setup.

The required modules are correctly imported, including the nursery setup, assertions, and the language registration.

packages/rust/index.js (2)

1-9: Well-structured language registration for Rust!

The code correctly sets up the Rust language registration for ast-grep with all the necessary properties. The implementation follows the pattern used by other language packages in the ast-grep ecosystem.


7-8:

✅ Verification successful

Confirm that 'tree_sitter_rust' and 'µ' are the correct values.

The languageSymbol and expandoChar values are crucial for proper language parsing. Ensure these values align with the tree-sitter-rust library expectations.


🏁 Script executed:

#!/bin/bash
# Check if the tree-sitter-rust library exports the expected symbol
rg -A 2 -B 2 "tree_sitter_rust" --type js --type rust

# Additionally, verify if other language packages use similar patterns for expandoChar
rg -A 1 -B 1 "expandoChar" --type js --glob "packages/*/index.js" | grep -v "packages/rust/index.js"

Length of output: 1430


Verified: 'tree_sitter_rust' and 'µ' are correctly set in packages/rust/index.js

I've confirmed via search that:

  • The file uses languageSymbol: 'tree_sitter_rust' exactly as expected by the tree-sitter-rust library.
  • The expandoChar is properly set to 'µ', consistent with similar patterns in other language package files (e.g., Python, C#, Go).

No changes are needed.

packages/rust/package.json (8)

6-12: Scripts follow the standard pattern for ast-grep language packages.

The scripts section correctly includes all necessary commands for building, testing, and package management, following the pattern used by other ast-grep language packages.


13-20: Files list looks complete.

The files array properly includes all necessary files for the package distribution.


24-26: Dependency on @ast-grep/setup-lang looks correct.

The dependency on @ast-grep/setup-lang is appropriate for a language package.


27-34: Optional peer dependency on tree-sitter-cli is correctly configured.

The peer dependency configuration with optional: true is appropriate for this use case.


40-43: Publishing configuration is appropriately set.

The publishConfig section correctly configures the package for public access on the npm registry.


44-46: PNPM configuration looks appropriate.

The PNPM configuration correctly specifies built dependencies.


23-23:

❌ Incorrect review comment

Consider using MIT license instead of ISC.

Most ast-grep packages use MIT license. Consider aligning this package with the project's typical licensing approach.


🏁 Script executed:

#!/bin/bash
# Check licenses used by other ast-grep packages
rg '"license"' --type json --glob "packages/*/package.json" | grep -v "packages/rust/package.json"

Length of output: 474


License Consistency Verified – No Change Needed

After verifying the licenses across the ast-grep packages, we found that all packages—including those in toml, sql, python, go, csharp, c, cpp, angular—use the ISC license. The current configuration in packages/rust/package.json is consistent with the rest of the project. Please disregard the previous suggestion to change to the MIT license.

Likely an incorrect or invalid review comment.


35-39:

✅ Verification successful

Verify the tree-sitter-rust version.

The package uses tree-sitter-rust version 0.23.2. Ensure this is the latest stable version that's compatible with the project.


🌐 Web query:

What is the latest stable version of tree-sitter-rust?

💡 Result:

The latest stable version of tree-sitter-rust is 0.23.2, as evidenced by multiple sources:

  • The Arch Linux package (last updated December 14, 2024) lists version 0.23.2-1[5]
  • The npm package shows version 0.23.2 published 4 months ago (as of April 2025)[8]

This version is compatible with Tree-sitter core library v0.25.3, the latest stable version of the main parser generator[9]. The package provides Rust grammar support for incremental parsing and syntax tree generation, featuring a 2-3× initial parse time compared to rustc's parser but sub-millisecond update times for edited code[4][8].

Citations:


Tree-sitter-rust version confirmed as current

After verifying with multiple external sources, version 0.23.2 is indeed the latest stable release. No changes are necessary for the dependency in packages/rust/package.json.

@NatoBoram NatoBoram force-pushed the feature/rust branch 2 times, most recently from 4089d6d to 90173d4 Compare April 4, 2025 21:02
@HerringtonDarkholme HerringtonDarkholme merged commit 571fc24 into ast-grep:main Apr 5, 2025
3 checks passed
@NatoBoram NatoBoram deleted the feature/rust branch April 6, 2025 03:31
This was referenced Apr 6, 2025
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