Skip to content

✨ TypeScript #65

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 4 commits into from
Apr 13, 2025
Merged

Conversation

NatoBoram
Copy link
Collaborator

@NatoBoram NatoBoram commented Apr 10, 2025

Summary by CodeRabbit

  • New Features
    • Launched a dedicated TypeScript language support package with enhanced parsing capabilities and file extension handling.
    • Integrated automated post-install setup for seamless configuration.
  • Documentation
    • Added comprehensive installation and integration instructions with clear usage examples for the TypeScript language support package.
  • Tests
    • Implemented tests to validate reliable TypeScript parsing and support functionality.

Copy link

coderabbitai bot commented Apr 10, 2025

Walkthrough

This pull request introduces a new TypeScript language support package for AST Grep. It adds a changeset entry and several new files under the packages/typescript directory. These files include a README with installation instructions, type definitions, implementation of the language registration, a nursery test setup, a package manifest with dependencies, and a post-install script. Collectively, the changes establish the infrastructure to parse TypeScript files using the new package.

Changes

File(s) Changed Summary
.changeset/warm-streets-type.md Added an entry noting the addition of the @ast-grep/lang-typescript package as a patch.
packages/typescript/README.md Introduced a README detailing installation instructions, usage examples, and integration steps for TypeScript language support.
packages/typescript/index.d.ts and packages/typescript/index.js Defined a new type (LanguageRegistration), created and exported the registration object with properties such as libraryPath, extensions, etc.
packages/typescript/nursery.js Added a testing setup using @ast-grep/nursery that registers TypeScript support and validates the parsing of a sample TypeScript declaration.
packages/typescript/package.json Created package metadata for @ast-grep/lang-typescript, including dependencies, scripts, publishing configurations, and pnpm settings.
packages/typescript/postinstall.js Added a post-installation script that invokes a setup function from @ast-grep/setup-lang for post-install tasks in the current directory.

Sequence Diagram(s)

sequenceDiagram
    participant Nursery as Nursery Test Runner
    participant Config as Language Registration (index.js / index.d.ts)
    participant Parser as TypeScript Parser Engine

    Nursery->>Config: Import registration object
    Config-->>Nursery: Provide libraryPath, extensions, languageSymbol, expandoChar
    Nursery->>Parser: Invoke parsing on TypeScript code ("let x: number = 123")
    Parser-->>Nursery: Return syntax tree with root node and node kind
Loading

Possibly related PRs

  • ✨ Tsx #66: The changes in the main PR, which involve the addition of the @ast-grep/lang-typescript package, are related to the changes in the retrieved PR that also introduces a new package, @ast-grep/lang-tsx, as both packages are part of the same project and involve similar structures and functionalities.

Suggested reviewers

  • HerringtonDarkholme

Poem

I’m a rabbit in a field of code,
Hopping through changes on a joyful road.
TypeScript support now takes its place,
With tests and scripts in every space.
Leaping high, I cheer these lines with grace!


📜 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 3c71158 and 83b7902.

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

🪧 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: 3

🧹 Nitpick comments (3)
packages/typescript/README.md (1)

1-25: Good documentation, but could be enhanced with more context.

The README provides clear installation instructions and a basic usage example, which is great. Consider enhancing it with:

  1. A brief introduction explaining what AST Grep is and why it's valuable for TypeScript users
  2. More advanced usage examples (e.g., searching for specific patterns in TypeScript code)
  3. Notes on compatibility with different TypeScript versions

Here's a suggestion for an introduction section to add at the beginning:

 # ast-grep napi language for typescript
+
+[ast-grep](https://ast-grep.github.io/) is a CLI tool for syntactically-aware code search, 
+powered by concrete syntax trees. This package adds TypeScript language support to ast-grep, 
+allowing you to search and manipulate TypeScript code with high precision.

 ## Installation
packages/typescript/package.json (2)

4-4: Add a descriptive package description.

The description field is empty. Adding a clear description would help users understand the purpose of this package.

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

22-22: Add author information.

The author field is empty. Adding author information provides proper attribution for the package.

-  "author": "",
+  "author": "AST Grep Team",
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f3631de and 3c71158.

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

1-6: LGTM! Changeset correctly defined.

The changeset properly specifies the new @ast-grep/lang-typescript package as a patch release with an appropriate description.

packages/typescript/postinstall.js (1)

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

The script correctly leverages the shared implementation from @ast-grep/setup-lang and provides the current directory for installation.

packages/typescript/index.d.ts (1)

1-10:

✅ Verification successful

LGTM! Type definitions are clear and complete.

The LanguageRegistration type properly defines the structure needed for language registration with both required and optional properties.


🏁 Script executed:

#!/bin/bash
# Check if the corresponding implementation file exists
ls packages/typescript/index.js
echo "Checking the implementation of the registration object:"
cat packages/typescript/index.js

Length of output: 448


LGTM! The type definition in packages/typescript/index.d.ts is clear and complete, and the corresponding implementation in packages/typescript/index.js exists and correctly instantiates the registration object.

  • The LanguageRegistration type accurately defines required (libraryPath, extensions) and optional (languageSymbol, metaVarChar, expandoChar) properties.
  • The implementation file correctly sets the properties (excluding the optional metaVarChar, which is acceptable) and constructs the libraryPath using node:path.
packages/typescript/nursery.js (1)

1-18: LGTM: Test setup correctly configured.

The nursery.js file properly sets up the testing environment for TypeScript using the @ast-grep/nursery package. The test runner successfully verifies basic parsing functionality by checking if a lexical declaration is correctly identified.

packages/typescript/index.js (1)

1-9: LGTM: Language registration is properly configured.

The language registration exports the necessary configuration for TypeScript parsing, including the library path, language symbol, and expando character.

@NatoBoram NatoBoram force-pushed the feature/typescript branch from 3c71158 to 83b7902 Compare April 10, 2025 20:05
@HerringtonDarkholme HerringtonDarkholme merged commit 484e355 into ast-grep:main Apr 13, 2025
3 checks passed
@NatoBoram NatoBoram deleted the feature/typescript branch April 16, 2025 20:59
@coderabbitai coderabbitai bot mentioned this pull request Apr 22, 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.

more languages in the monorepo?
2 participants