Skip to content

✨ Dart #48

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 4, 2025
Merged

✨ Dart #48

merged 3 commits into from
Apr 4, 2025

Conversation

NatoBoram
Copy link
Collaborator

@NatoBoram NatoBoram commented Apr 2, 2025

Actually one of my favourite languages :P

Summary by CodeRabbit

  • Documentation

    • Added comprehensive instructions on installing and using the new Dart language support package.
  • New Features

    • Launched a Dart language support package that enables dynamic language registration and robust code parsing.
    • Introduced new type definitions and constants for Dart language support.
    • Added a new testing setup for Dart language functionality.
  • Chores

    • Introduced a package.json file for managing package metadata and dependencies.
    • Added post-installation script to facilitate setup tasks for the Dart package.

Copy link

coderabbitai bot commented Apr 2, 2025

Walkthrough

This PR introduces support for the Dart language in the AST-Grep ecosystem. It adds a new package (@ast-grep/lang-dart) along with a corresponding README, type definitions, and runtime registration logic. Additionally, it includes a test setup file using @ast-grep/nursery to validate Dart parsing, and a post-install script to automate setup tasks during package installation.

Changes

File(s) Change Summary
packages/dart/README.md New README detailing installation and usage for Dart language support and NAPI library instructions.
packages/dart/index.d.ts, packages/dart/index.js Added language registration definitions and exports with properties (libraryPath, extensions, languageSymbol, expandoChar) for Dart language support.
packages/dart/nursery.js Introduced a test runner for Dart using @ast-grep/nursery that parses Dart code and validates AST node kinds.
packages/dart/package.json New package configuration for @ast-grep/lang-dart with metadata, dependencies (including @ast-grep/napi and tree-sitter-cli), scripts, and publish settings.
packages/dart/postinstall.js Added a post-install script that invokes the setup function from @ast-grep/setup-lang using the current directory to perform post-installation tasks.

Sequence Diagram(s)

sequenceDiagram
    participant Nursery as Nursery.js
    participant Registration as Language Module
    participant Parser as Tree-sitter Parser
    Nursery->>Registration: Import language registration data
    Nursery->>Parser: Initialize parser with registration details
    Parser-->>Nursery: Return syntax tree
    Nursery->>Nursery: Validate AST nodes
Loading
sequenceDiagram
    participant Installer as Package Manager
    participant PostInstall as postinstall.js
    participant SetupLang as @ast-grep/setup-lang
    Installer->>PostInstall: Run postinstall script
    PostInstall->>SetupLang: Invoke setup with __dirname
    SetupLang-->>PostInstall: Complete post-installation tasks
Loading

Possibly related PRs

  • ✨ Bash #46: The changes in the main PR for the Dart package and the retrieved PR for the Bash package both introduce a new LanguageRegistration type definition and a registration constant, indicating a shared structure for language support.
  • feat: C# language #41: The changes in the main PR for the Dart language package are related to those in the retrieved PR for the C# language package, as both introduce a new LanguageRegistration type definition and a similar structure for their respective README, index, and postinstall files.

Suggested reviewers

  • HerringtonDarkholme

Poem

I'm a bunny of code, with hops so spry,
Dart paths and tests make my heart fly high.
I nibble through syntax with a twitch and a grin,
Where language trees grow, let the parsing begin!
With bytes and joy, I celebrate the new spin 🐇✨
Happy coding in the meadows of AST!


🪧 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 (6)
packages/dart/nursery.js (1)

1-16: LGTM! Test setup follows the standard pattern.

The nursery script properly sets up a testing environment for Dart language parsing with a simple but effective validation test to ensure the parser can correctly identify an identifier.

Consider expanding test coverage in the future to include more complex Dart language constructs, such as:

  • Class definitions
  • Function declarations
  • Type annotations
  • Dart-specific syntax like async/await
packages/dart/README.md (1)

1-24: LGTM! Documentation contains essential information.

The README provides clear installation and usage instructions that follow the standard format for AST-Grep language packages.

Consider these enhancements to make the documentation more helpful for new users:

  1. Add a brief description of what the package does and its purpose
  2. Include a more complete usage example showing actual results
  3. Add a link to the main AST-Grep documentation
  4. Specify whether the example uses ES modules or provide a CommonJS alternative
packages/dart/index.d.ts (1)

1-10: LGTM! Type definitions match the expected interface.

The TypeScript declarations correctly define the LanguageRegistration type with all the required properties and properly export the registration object.

Consider adding JSDoc comments to explain the purpose of each property, especially the less obvious ones like metaVarChar and expandoChar, to make the code more self-documenting:

type LanguageRegistration = {
+  /** Path to the language library (.so/.dll) */
  libraryPath: string
+  /** File extensions associated with this language */
  extensions: string[]
+  /** Symbol name for the language in the library */
  languageSymbol?: string
+  /** Character used for meta variables in pattern matching */
  metaVarChar?: string
+  /** Character used for multi-meta variables in pattern matching */
  expandoChar?: string
}
packages/dart/package.json (3)

1-5: Enhance Package Metadata
The basic package metadata is correctly established. However, the "description" field is left empty. Providing a concise description (e.g., "Dart language support for AST-Grep") will improve clarity on registries and package listings.

-  "description": "",
+  "description": "Dart language support for AST-Grep",

13-20: Files Array Validation
The files array includes all necessary artifacts for publishing. Confirm that including both "index.d.ts" and "type.d.ts" is intentional and that they serve distinct purposes.


21-23: Metadata Details Improvement
While the keywords, author, and license fields are present, consider adding proper author details for correct 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 856c768.

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

1-4: LGTM! Postinstall script follows the standard pattern.

The implementation correctly imports and uses the postinstall function from @ast-grep/setup-lang, following the established pattern used in other language packages.

packages/dart/index.js (2)

1-2: Modern Import Usage
The use of require('node:path') is appropriate for recent Node.js versions. If backward compatibility for older Node.js versions is a concern, ensure this import style is acceptable.


4-9: Clear and Concise Export Structure
The exported object clearly defines the properties needed for Dart language support. Each key (i.e. libraryPath, extensions, languageSymbol, and expandoChar) is appropriately set, ensuring ease of use for downstream consumers.

packages/dart/package.json (7)

6-12: Review of Scripts Section
The defined scripts for building, sourcing, prepublishing, post-installation, and testing are in line with standard package lifecycle operations. Ensure that commands like "prepublishOnly": "node nursery.js source" behave as expected in your CI/CD pipeline.


24-26: Dependencies Declaration
The dependency on @ast-grep/setup-lang is clearly declared with version "0.0.3". Double-check that this version aligns with your project’s expectations and that it is compatible with the Dart language support tooling.


27-29: Peer Dependency Check
The peer dependency on "tree-sitter-cli" is specified correctly. Verify that this version ("0.24.6") satisfies the requirements from other related packages.


30-34: Optional Peer Dependency Setup
The configuration under peerDependenciesMeta correctly marks "tree-sitter-cli" as optional, which enhances installation flexibility.


35-39: Dev Dependencies Verification
The dev dependencies are aptly listed for testing and building, including @ast-grep/nursery, tree-sitter-cli, and tree-sitter-dart. Confirm that these versions ("0.0.2", "0.24.6", and "1.0.0", respectively) integrate smoothly with your build and test workflow.


40-43: Publish Configuration
The publishConfig section is well-formed for ensuring public publication to npm. This will aid in streamlining the package deployment process.


44-46: PNPM Configuration Appropriateness
The pnpm configuration specifying "onlyBuiltDependencies" for @ast-grep/lang-dart and tree-sitter-cli looks correct. Revisit this list if additional dependencies need bundling in future releases.

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 (3)
packages/dart/package.json (3)

1-5: Suggestion: Enhance Package Metadata
The basic metadata is correctly defined; however, the "description" field is currently empty. Adding a brief description would improve package discoverability and help users understand its purpose.


6-12: Review: Validate Package Scripts
The scripts (build, source, prepublishOnly, postinstall, and test) are clearly defined and align with managing the package lifecycle. Please ensure that the tree-sitter commands (e.g., tree-sitter build -o parser.so) work uniformly across different platforms and environments.


21-23: Suggestion: Complete Package Fields
Consider updating the "author" field with proper contact information or attribution, and filling out the "description" field to provide clarity on the package's functionality and benefits.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 56a9107 and 201d604.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (7)
  • .changeset/yummy-hats-sniff.md (1 hunks)
  • packages/dart/README.md (1 hunks)
  • packages/dart/index.d.ts (1 hunks)
  • packages/dart/index.js (1 hunks)
  • packages/dart/nursery.js (1 hunks)
  • packages/dart/package.json (1 hunks)
  • packages/dart/postinstall.js (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (6)
  • packages/dart/postinstall.js
  • packages/dart/README.md
  • packages/dart/index.js
  • .changeset/yummy-hats-sniff.md
  • packages/dart/nursery.js
  • packages/dart/index.d.ts
🔇 Additional comments (5)
packages/dart/package.json (5)

13-20: Confirmation: Package Files Inclusion
The "files" array includes all the necessary files (index.js, TypeScript definitions, postinstall.js, and source directories). This setup should guarantee that consumers get the complete set of required assets.


24-34: Review: Dependencies and Peer Dependencies
The dependency on "@ast-grep/setup-lang": "0.0.3" and the peer dependency on "tree-sitter-cli": "0.24.6" (with its optional flag) are appropriately declared. Verify that these version specifications align with the broader ecosystem and that downstream packages are aware of these requirements.


35-39: Confirmation: Dev Dependencies Setup
The development dependencies (including "@ast-grep/nursery", "tree-sitter-cli", and "tree-sitter-dart") are well specified to support testing and parser building.


40-43: Validation: Publish Configuration
The "publishConfig" is correctly set to publish the package publicly to the npm registry, ensuring easy access for users.


44-46: Evaluation: pnpm Configuration
The pnpm configuration, targeting only built dependencies ("@ast-grep/lang-dart" and "tree-sitter-cli"), is properly specified. This helps keep the final package lean and ensures that only necessary assets are distributed.

@HerringtonDarkholme HerringtonDarkholme merged commit bc9a5f3 into ast-grep:main Apr 4, 2025
3 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Apr 4, 2025
@NatoBoram NatoBoram deleted the feature/dart branch April 4, 2025 21:04
This was referenced Apr 4, 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