Skip to content

✨ Elixir #49

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

Conversation

NatoBoram
Copy link
Collaborator

@NatoBoram NatoBoram commented Apr 2, 2025

A very fun language to learn. Functional programming is kinda mind-blowing.

Summary by CodeRabbit

  • New Features
    • Introduced comprehensive support for the Elixir language, enabling enhanced parsing and integration.
  • Documentation
    • Added detailed installation and usage instructions to guide users in setting up Elixir language support.
  • Tests
    • Established a testing setup to validate the functionality of the Elixir parsing capabilities.
  • Chores
    • Included package configuration and post-installation routines to streamline integration and deployment.

Copy link

coderabbitai bot commented Apr 2, 2025

Walkthrough

This pull request introduces Elixir language support for the AST grep tool. It provides a new README with installation and usage instructions, defines and exports a new language registration type and configuration in both TypeScript and JavaScript files, and includes scripts for package installation and testing. A testing setup file (nursery.js) configures a test environment using a sample Elixir code snippet, while the package metadata (package.json) and a post-install script complete the integration.

Changes

File(s) Change Summary
packages/elixir/README.md Added documentation with installation instructions, usage examples, and integration guidelines for the Elixir language package.
packages/elixir/index.d.ts & packages/elixir/index.js Introduced the LanguageRegistration type and exported a constant with parser configuration (libraryPath, extensions, languageSymbol, expandoChar).
packages/elixir/nursery.js Created a testing setup using @ast-grep/nursery to validate parsing of Elixir code.
packages/elixir/package.json Added package metadata, dependencies, build/test scripts, and publish configuration for @ast-grep/lang-elixir.
packages/elixir/postinstall.js Implemented a post-install script to execute additional setup using @ast-grep/setup-lang.
.changeset/four-falcons-chew.md Added entry for the @ast-grep/lang-elixir package in the changeset.

Sequence Diagram(s)

sequenceDiagram
    participant T as Test Runner (nursery.js)
    participant N as Nursery Setup (@ast-grep/nursery)
    participant L as Language Registration (index.js / index.d.ts)
    participant P as Parser Library
    T->>N: Invoke setup(config with L)
    N->>L: Retrieve language configuration
    L->>P: Load parser using libraryPath and extensions
    P-->>L: Provide parser instance
    N->>T: Complete setup and run parsing test
    T->>P: Parse sample code "IO.puts(\"123\")"
    P-->>T: Return AST structure
    T->>T: Assert node kind is 'call'
Loading
sequenceDiagram
    participant NPM as npm install
    participant P as postinstall.js
    participant S as @ast-grep/setup-lang
    NPM->>P: Trigger postinstall script
    P->>S: Execute postinstall({ dirname: __dirname })
    S-->>P: Complete language-specific setup
Loading

Suggested reviewers

  • HerringtonDarkholme

Poem

I’m a bunny with a keen coder’s ear,
Leaping through files with a joyful cheer.
New Elixir support makes my heart race,
Parsing code with elegance and grace.
Hopping through changes, bright as day—
CodeRabbit celebrates in a rabbit way! 🐇
Happy coding under the moon’s soft ray!


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b88310b and c97bc12.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (7)
  • .changeset/four-falcons-chew.md (1 hunks)
  • packages/elixir/README.md (1 hunks)
  • packages/elixir/index.d.ts (1 hunks)
  • packages/elixir/index.js (1 hunks)
  • packages/elixir/nursery.js (1 hunks)
  • packages/elixir/package.json (1 hunks)
  • packages/elixir/postinstall.js (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (7)
  • packages/elixir/postinstall.js
  • packages/elixir/index.d.ts
  • packages/elixir/nursery.js
  • packages/elixir/README.md
  • packages/elixir/index.js
  • packages/elixir/package.json
  • .changeset/four-falcons-chew.md

🪧 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 (2)
packages/elixir/package.json (2)

4-4: Add a descriptive package description.

The description field is currently empty. Adding a clear description will help users understand the purpose of this package when browsing the npm registry.

-  "description": "",
+  "description": "Elixir language support for ast-grep",

22-22: Add author information.

The author field is currently empty. Consider adding appropriate author information for attribution and contact purposes.

-  "author": "",
+  "author": "NatoBoram <[email protected]>",
📜 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 cadc673.

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

1-4: Implementation looks good!

The postinstall script correctly imports and calls the setup function with the current directory, following the standard pattern for ast-grep language packages.

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

1-7: Type definition looks complete and appropriate.

The LanguageRegistration type properly defines all required fields (libraryPath, extensions) and optional configuration fields (languageSymbol, metaVarChar, expandoChar) needed for Elixir language support in ast-grep.


9-10: Export declaration is correct.

The type declaration and default export of the registration constant follows proper TypeScript patterns and will work correctly with the implementation file.

packages/elixir/nursery.js (2)

1-4: Correct import setup for testing environment.

The necessary modules are properly imported for setting up the test environment, including the nursery setup function, Node.js assert module, and the language registration.


5-16: Test configuration and runner look good.

The setup configuration correctly specifies:

  • The Elixir language name
  • The appropriate Tree-sitter package ('tree-sitter-elixir')
  • A test runner that validates basic parsing and pattern matching

The test case effectively verifies that an Elixir function call is correctly parsed and can be matched with a pattern containing a metavariable.

packages/elixir/README.md (3)

1-2: Clear and concise title.

The title accurately describes the package as an ast-grep NAPI language for Elixir.


3-12: Installation instructions are complete.

The installation section properly covers all required dependencies:

  • The Elixir language package itself
  • The NAPI package requirement
  • The conditional installation of tree-sitter-cli

This provides users with a complete setup process for using Elixir with ast-grep in a pnpm environment.


14-24: Usage example is clear and helpful.

The example demonstrates the complete workflow:

  1. Importing the necessary modules
  2. Registering the Elixir language
  3. Parsing Elixir code
  4. Accessing the AST

This gives users a practical reference for implementing Elixir support in their projects.

packages/elixir/index.js (1)

1-9: LGTM! Elixir language configuration is well-structured.

The configuration exports all the necessary components for integrating Elixir with ast-grep:

  • Correctly uses node:path module
  • Properly references the parser.so file in the same directory
  • Includes appropriate file extensions for Elixir (.ex and .exs)
  • Sets the proper language symbol for Tree-sitter
  • Defines an expandoChar that's unlikely to conflict with Elixir syntax

The implementation follows the expected pattern for language packages in ast-grep.

packages/elixir/package.json (3)

6-12: LGTM! Scripts setup is comprehensive.

The scripts section is well-configured with all necessary lifecycle hooks:

  • Build script for creating the parser
  • Source and prepublishOnly scripts for preparation
  • Postinstall script for setup after installation
  • Test script for verification

This provides a complete workflow for development, testing, and distribution.


13-20: LGTM! Package files are properly configured.

The files array correctly includes all necessary components:

  • Main module file
  • Type definitions
  • Installation script
  • Source code
  • Prebuilt binaries

This ensures the package will be complete when published to npm.


35-39:

✅ Verification successful

Verify tree-sitter-elixir version.

The package uses tree-sitter-elixir at version 0.3.4. Please verify this is the latest stable version that properly supports the Elixir language syntax.


🌐 Web query:

What is the latest version of tree-sitter-elixir?

💡 Result:

The latest version of tree-sitter-elixir is 0.3.4, released on February 6, 2025[2]. This version is available on package managers like npm and Rust's crates.io[2][5]. The project continues to be actively maintained, with GitHub using it for Elixir syntax highlighting and code navigation[2][5][6].

For context:

  • Previous versions include 0.3.3 (December 2024) and 0.2.0 (April 2024)[2][9]
  • The parser handles modern Elixir syntax including LiveView Native templates and improved error handling[9]
  • Bindings exist for multiple languages including Rust, JavaScript (through npm), and Elixir itself via the ex_tree_sitter package[1][4][5]

Citations:


Tree-sitter-elixir version verified as up-to-date

After verifying the latest release from the official sources, it's confirmed that version 0.3.4 is indeed the latest stable release for tree-sitter-elixir. No modifications are needed in the packages/elixir/package.json as the dependency is current.

@NatoBoram NatoBoram force-pushed the feature/elixir branch 2 times, most recently from b88310b to 3359e14 Compare April 4, 2025 19:38
@HerringtonDarkholme HerringtonDarkholme merged commit 8e792b5 into ast-grep:main Apr 5, 2025
3 checks passed
@NatoBoram NatoBoram deleted the feature/elixir branch April 5, 2025 06:35
@coderabbitai coderabbitai bot mentioned this pull request 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