-
Notifications
You must be signed in to change notification settings - Fork 6
✨ 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
✨ Rust #58
Conversation
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 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. ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (7)
WalkthroughThis 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
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)
Possibly related PRs
Suggested reviewers
Poem
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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
⛔ 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
andexpandoChar
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:
- 1: https://github.com/tree-sitter/tree-sitter/releases
- 2: https://launchpad.net/ubuntu/+source/rust-tree-sitter-config/+publishinghistory
- 3: https://pypi.org/project/tree-sitter-languages/
- 4: https://github.com/tree-sitter/tree-sitter-rust
- 5: https://archlinux.org/packages/extra/x86_64/tree-sitter-rust/
- 6: https://crates.io/crates/tree-sitter-rstml
- 7: https://docs.rs/tree-sitter
- 8: https://www.npmjs.com/package/tree-sitter-rust
- 9: https://formulae.brew.sh/formula/tree-sitter
- 10: https://github.com/tree-sitter/tree-sitter
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
.
4089d6d
to
90173d4
Compare
Summary by CodeRabbit
New Features
Documentation
Tests