Skip to content

feat: add typescript import identifiers example #729

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 1 commit into from
Apr 12, 2025

Conversation

michaelangeloio
Copy link
Contributor

@michaelangeloio michaelangeloio commented Apr 12, 2025

Thank you, @HerringtonDarkholme and other contributors, for this awesome project!

I'm currently learning ast-grep. We're looking to use this at GitLab for our AST Code Parser project.

I wanted to see if I could replicate all the logic built here for our JS import parser in the Language Server. We built this parser to extract imports for AI Code Suggestions (you can read more at this epic).

I decided to contribute back as soon as I got something working. If y'all think there's a more straightforward way to achieve the same metadata extraction, by all means, please suggest changes!

Thank you!

Summary by CodeRabbit

  • Documentation
    • Introduced an extensive guide that explains how to extract various TypeScript import identifiers using different patterns and configuration setups.
    • Provides detailed examples and guidelines for handling alias, default, dynamic, side-effect, and namespace imports, ensuring clear best practices for efficient import analysis.

Copy link

coderabbitai bot commented Apr 12, 2025

Walkthrough

A new documentation file, find-import-identifiers.md, has been added to the TypeScript catalog. This guide details how to extract various import identifiers from TypeScript code. It covers multiple import types—including alias, default, dynamic, side effect, and namespace imports—using specific YAML rules and patterns. The document includes example code snippets and comments to help capture the relevant metadata, providing a structured approach for developers to analyze and process import statements.

Changes

Files Changed Summary
.../typescript/find-import-identifiers.md Added a comprehensive guide detailing YAML patterns for extracting different TypeScript import identifiers with examples of alias, default, dynamic, side effect, and namespace imports.

Sequence Diagram(s)

Poem

Hi, I'm a bunny, so light on my feet,
Hopping through docs with a cheerful beat.
A guide on imports now graces our tree,
YAML magic for code, joyful and free.
I cherish each change with a twitch and a smile,
Celebrating with hops that go the extra mile!

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 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 (3)
website/catalog/typescript/find-import-identifiers.md (3)

5-13: Description Section & Bullet List Markdown Formatting

The description is well written and lists the various import scenarios clearly. However, in the "Default & Regular Imports" bullet (line 10), it appears that the inline code formatting may be off—a closing backtick is missing after the import statement. Correcting this will ensure consistent markdown rendering.


15-231: Comprehensive YAML Rules for Import Extraction

The YAML section is very thorough and clearly documents rules for different import types (alias, default, regular, dynamic, namespace, and side-effect imports). One minor suggestion: in the REGULAR IMPORTS section (e.g., around lines 67–74), the comment states "ensure it has an 'alias' field" while the actual rule checks the name field against $ORIGINAL. To avoid confusion, consider updating the comment to clarify that it is capturing the original identifier (or, if intended otherwise, adjust the rule accordingly).


232-296: Thorough Example Code Snippet

The TypeScript code snippet effectively demonstrates a wide range of import scenarios, which will greatly help users understand how the rules apply. One minor enhancement: for the dynamic import examples (e.g., line 286), it might be helpful to add a brief note (or inline comment) clarifying that destructuring from an import() call typically requires awaiting the promise, even if this is just for illustrative purposes.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4eb9295 and 2b6c237.

📒 Files selected for processing (1)
  • website/catalog/typescript/find-import-identifiers.md (1 hunks)
🔇 Additional comments (2)
website/catalog/typescript/find-import-identifiers.md (2)

1-3: Great Introduction and Informative Playground Link

The document opens with a clear, descriptive title and a useful playground link. Please verify that the base64 query parameters in the URL correctly encode the intended configuration and render as expected on the playground.


298-301: Contributor Acknowledgment is Clear

The acknowledgment section properly credits the contributor with a direct link to their GitHub profile. This section is clear and serves its purpose.

Copy link
Member

@HerringtonDarkholme HerringtonDarkholme left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@HerringtonDarkholme HerringtonDarkholme added this pull request to the merge queue Apr 12, 2025
Merged via the queue into ast-grep:main with commit a57c681 Apr 12, 2025
1 check passed
@HerringtonDarkholme
Copy link
Member

Hi, I'm glad that GitLab is considering ast-grep as a tool to parse code.

replicate all the logic built here

To my best knowledge, ast-grep should be at least as good as tree-sitter's query. ast-grep also supports advanced rule like recursive utility which is not possible in tree-sitter query.

a more straightforward way to achieve the same metadata extraction

Unfortunately, AST handling isn't always easy, especially when you are building a generic tool. Global utility rule can help you organize the rule a little bit.

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
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy