Skip to content

✨ JSON #54

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

✨ JSON #54

merged 3 commits into from
Apr 6, 2025

Conversation

NatoBoram
Copy link
Collaborator

@NatoBoram NatoBoram commented Apr 2, 2025

Summary by CodeRabbit

  • New Features

    • Introduced JSON language support to enhance parsing capabilities.
    • Added a new package @ast-grep/lang-json for JSON parsing.
  • Documentation

    • Provided clear installation and usage guides for the new JSON support package.
  • Tests

    • Added tests to verify the functionality of JSON parsing.

Copy link

coderabbitai bot commented Apr 2, 2025

Walkthrough

This pull request introduces the @ast-grep/lang-json package to the repository. The changes encompass the addition of documentation, type definitions, module exports, a testing setup, package metadata, and a post-installation script. A changeset entry also records this addition as a patch. The new package is designed to facilitate JSON language parsing within the ast-grep framework.

Changes

File(s) Summary
.changeset/smart-moose-sniff.md Documented the addition of @ast-grep/lang-json as a patch.
packages/json/README.md, packages/json/package.json Introduced the new package with installation instructions, metadata, and script definitions for building, testing, and post-install tasks.
packages/json/index.d.ts, packages/json/index.js Added type definitions and module exports defining the JSON language registration (including properties like libraryPath, extensions, languageSymbol, and expandoChar).
packages/json/nursery.js Established a testing setup for JSON parsing using @ast-grep/nursery.
packages/json/postinstall.js Implemented a post-installation hook calling @ast-grep/setup-lang for configuration.

Suggested Reviewers

  • HerringtonDarkholme

Poem

Oh, how I hop with glee,
A rabbit coder, wild and free.
JSON now finds its home, anew,
In ast-grep’s realm, with code so true.
With whiskers twitching, I celebrate—
A patch of magic, oh so great!
🐰✨


📜 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 ecbe836 and 3dbc026.

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

🪧 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.

@NatoBoram NatoBoram force-pushed the feature/json branch 2 times, most recently from 45affb7 to 341d8ce Compare April 4, 2025 21:02
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 (5)
packages/json/index.d.ts (1)

1-7: Consider adding JSDoc comments to improve documentation.

The LanguageRegistration type is well-structured with the appropriate properties. Consider adding JSDoc comments to document each field's purpose for better developer experience.

+/**
+ * Registration metadata for a language in ast-grep.
+ */
 type LanguageRegistration = {
+  /** Path to the language library */
   libraryPath: string
+  /** Array of file extensions supported by this language */
   extensions: string[]
+  /** Optional symbol representing the language */
   languageSymbol?: string
+  /** Character used for meta variables */
   metaVarChar?: string
+  /** Character used for expando variables */
   expandoChar?: string
 }
packages/json/nursery.js (1)

5-16: Expand test coverage for more comprehensive validation.

While the basic test setup is functional, it only tests a simple case with one assertion. Consider expanding the test suite to cover:

  1. Different JSON structures (arrays, nested objects)
  2. Various value types (strings, numbers, booleans, null)
  3. Edge cases (empty objects, arrays)

This would provide greater confidence in the JSON parser's functionality.

 testRunner: parse => {
   const sg = parse('{"abc": 123}')
   const root = sg.root()
   const node = root.find('{ $$$ }')
   assert.equal(node.kind(), 'object')
+  
+  // Test JSON array
+  const sgArray = parse('[1, 2, 3]')
+  const arrayRoot = sgArray.root()
+  const arrayNode = arrayRoot.find('[ $$$ ]')
+  assert.equal(arrayNode.kind(), 'array')
+  
+  // Test nested structures
+  const sgNested = parse('{"nested": {"value": true, "array": [1, null]}}')
+  const nestedRoot = sgNested.root()
+  assert.equal(nestedRoot.find('{ "nested": $$$ }').kind(), 'object')
+  assert.equal(nestedRoot.find('true').kind(), 'true')
+  assert.equal(nestedRoot.find('null').kind(), 'null')
 },
packages/json/package.json (1)

1-48: Metadata Completeness: Populate 'description' and 'author' Fields
The package metadata is mostly complete; however, the "description" and "author" fields are currently empty. Populating these fields with relevant information will improve package discoverability and maintainability.

packages/json/index.js (1)

1-3: Correct Usage of Node.js Path Module
The use of node:path and path.join(__dirname, 'parser.so') is correct for constructing the path to parser.so. Ensure that the shared library is built and present when the module is loaded.

packages/json/README.md (1)

1-3: Clarify README Title for Consistency
The current title "ast-grep napi language for json" could be more descriptive. Consider updating it to explicitly reference JSON support (e.g., "@ast-grep/lang-json: JSON Language Module") to align with the package name.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between bc9a5f3 and 341d8ce.

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

1-6: LGTM! Changeset entry is properly structured.

The changeset correctly identifies the package name and version bump type (patch) for the new @ast-grep/lang-json package.

packages/json/postinstall.js (1)

1-5: LGTM! Post-installation script is properly configured.

The script correctly imports and calls the postinstall function from @ast-grep/setup-lang with the current directory.

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

9-10: LGTM! Proper export of the registration constant.

The registration constant is correctly declared and exported.

packages/json/nursery.js (1)

1-4: LGTM! Necessary dependencies are properly imported.

The required modules for testing are correctly imported.

packages/json/index.js (1)

4-9: Module Export for JSON Parsing Configuration
The exported object correctly defines the properties (libraryPath, extensions, languageSymbol, and expandoChar) required for JSON parsing. The implementation is clear and straightforward.

packages/json/README.md (2)

3-12: Clear Installation Instructions
The installation section clearly outlines the commands needed for a pnpm project, including the optional installation of @tree-sitter/cli. This provides users with straightforward guidance on setting up the package.


14-25: Well-Documented Usage Example
The usage section provides a concise and comprehensive example showing how to import and register the JSON language dynamically using @ast-grep/napi. This will help users quickly understand how to integrate the package.

@HerringtonDarkholme
Copy link
Member

oops, we are still having conflicts

@NatoBoram
Copy link
Collaborator Author

I suspect we're going to continue having these until the last one :P

@HerringtonDarkholme HerringtonDarkholme merged commit 9c4a800 into ast-grep:main Apr 6, 2025
3 checks passed
@NatoBoram NatoBoram deleted the feature/json branch April 6, 2025 04:23
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