Skip to content

✨ Swift #60

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

✨ Swift #60

merged 3 commits into from
Apr 5, 2025

Conversation

NatoBoram
Copy link
Collaborator

@NatoBoram NatoBoram commented Apr 3, 2025

Summary by CodeRabbit

  • New Features

    • Introduced a new Swift language support package enabling dynamic code parsing and seamless language registration.
    • Implemented an automated setup process to streamline installation.
  • Documentation

    • Added a comprehensive README with clear installation and usage instructions for the new Swift integration.
  • Type Definitions

    • Added a new type definition for LanguageRegistration to enhance type safety and clarity.
  • Testing

    • Established a testing environment for the Swift language, ensuring proper parsing and node identification.

Copy link

coderabbitai bot commented Apr 3, 2025

Warning

Rate limit exceeded

@NatoBoram has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 12 minutes and 42 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 4f41a5a and d738d59.

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

Walkthrough

This pull request introduces support for the Swift programming language in the ast-grep ecosystem. It adds a new package, @ast-grep/lang-swift, along with a README for installation and usage instructions. Type definitions, JavaScript implementations for language registration, and a testing setup using @ast-grep/nursery have been added. Additionally, a post-installation script facilitates setup, and the package is configured with the necessary metadata and dependencies.

Changes

File(s) Change Summary
packages/swift/README.md Adds a README with installation instructions using pnpm and usage examples, including code snippets for dynamic registration and parsing of Swift code.
packages/swift/index.d.ts
packages/swift/index.js
Introduces the LanguageRegistration type and a default exported registration object defining properties like libraryPath, extensions, languageSymbol, and expandoChar to support Swift parser integration.
packages/swift/nursery.js Creates a testing setup for Swift using @ast-grep/nursery, including a sample test that parses a Swift print statement and verifies the syntax node kind is call_expression.
packages/swift/package.json Introduces the new package @ast-grep/lang-swift with metadata, scripts for building/testing, dependency definitions including an optional peer dependency for tree-sitter-cli, and publish configuration.
packages/swift/postinstall.js Adds a post-installation script that calls the postinstall method from @ast-grep/setup-lang, passing the current directory for further configuration related to the Swift package.
.changeset/wild-jobs-poke.md Adds an entry indicating the inclusion of the @ast-grep/lang-swift package as a patch.

Possibly related PRs

  • feat: add tree-sitter-c #35: Introduces a new LanguageRegistration type and corresponding registration constant, relevant to language support in the @ast-grep/napi framework.
  • ✨ Bash #46: Similar introduction of a LanguageRegistration type and registration constant for the @ast-grep/lang-bash package, indicating a direct relationship.
  • ✨ Dart #48: Introduces a new package with a consistent structure, including a README.md, type definitions, and a JavaScript file, similar to the changes made for Swift.

Suggested reviewers

  • HerringtonDarkholme

Poem

Hopping through code with glee,
I nibble bugs and set them free.
Swift code blossoms on my path,
With nodes that dance in perfect math.
A bunny’s joy in every line—
Hoppy changes, simply divine! 🐰✨


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

4-4: Add a meaningful description

The description field is empty. Consider adding a descriptive summary like "Swift language support for ast-grep" to help users understand the package's purpose.


22-22: Add author information

The author field is empty. Consider adding the author information for proper attribution.


21-21: Consider adding more keywords

Adding more relevant keywords like "swift", "parser", "language", etc., would make the package more discoverable in npm searches.

packages/swift/nursery.js (1)

1-16: Consider adding more comprehensive test cases

While the current test verifies basic functionality, consider adding more complex test cases that cover a wider range of Swift syntax patterns (e.g., classes, protocols, closures).

For example:

testRunner: parse => {
  // Test 1: Basic function call
  let sg = parse('println("123")')
  let node = sg.root().find('println("123")')
  assert.equal(node.kind(), 'call_expression')
  
  // Test 2: Class definition
  sg = parse('class MyClass { func test() {} }')
  node = sg.root().find('class MyClass')
  assert.equal(node.kind(), 'class_declaration')
  
  // Test 3: Swift protocol
  sg = parse('protocol MyProtocol { func required() }')
  node = sg.root().find('protocol MyProtocol')
  assert.equal(node.kind(), 'protocol_declaration')
}
📜 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 c228df0.

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

1-4: LGTM! Clean and straightforward postinstall script.

The script correctly imports the postinstall function from @ast-grep/setup-lang and invokes it with the current directory, which is a standard pattern for language package setup in ast-grep.

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

1-7: Type definition looks good and follows the expected pattern.

The LanguageRegistration type correctly defines the interface for language registration with appropriate optional properties, matching what's needed for the Swift language implementation.


9-10: Export pattern is clean and follows TypeScript best practices.

The declaration and default export of the registration constant follows the standard pattern for ast-grep language packages.

packages/swift/index.js (2)

1-3: Path resolution looks correct.

Good use of the Node.js path module to ensure proper resolution of the parser library path regardless of the runtime environment.


4-9: Swift language configuration is properly defined.

The configuration correctly specifies:

  • Swift file extension
  • Tree-sitter symbol for Swift
  • An expando character for AST pattern matching

This follows the standard pattern used by other language packages in ast-grep.

packages/swift/README.md (2)

1-13: Installation instructions are clear and complete.

The README provides clear steps for installing the necessary packages in a pnpm project, including the optional development dependency for cases where prebuilt binaries aren't available.


14-24: Usage example is helpful and demonstrates the key functionality.

The code example effectively shows how to:

  1. Import the Swift language support
  2. Register the language dynamically
  3. Parse Swift code and access the AST

This gives users a good starting point for integrating Swift language support into their projects.

packages/swift/package.json (7)

3-4: Version number looks good for a new package

The initial version of 0.0.1 is appropriate for a new package that's just being introduced to the ecosystem.


6-12: Scripts look well structured

The scripts setup follows best practices with appropriate hooks for building, testing, and installation.


13-20: Package files list looks complete

The files to be included in the package are properly specified, including the necessary JavaScript files, type definitions, and prebuilt binaries.


24-26: Dependency version is pinned correctly

Using a specific version (0.0.3) for @ast-grep/setup-lang ensures consistency.


30-34: Optional peer dependency is appropriate

Making tree-sitter-cli an optional peer dependency is a good practice, allowing users to install it only if needed.


40-43: Publishing configuration is correct

The publishConfig section properly specifies public access and the npm registry.


27-29: ⚠️ Potential issue

Fix version mismatch in tree-sitter-cli dependency

The peerDependency version of tree-sitter-cli (0.24.6) doesn't match the version in devDependencies (0.24.6). This looks like a typo.

  "peerDependencies": {
-    "tree-sitter-cli": "0.24.6"
+    "tree-sitter-cli": "0.24.6"
  },

Likely an incorrect or invalid review comment.

packages/swift/nursery.js (3)

1-3: Import statements are clear and concise

The require statements properly import the necessary dependencies including the Node.js built-in assert module.


5-9: Setup configuration is correctly structured

The setup configuration includes all necessary parameters for the Swift language integration:

  • dirname set to current directory
  • name set to 'swift'
  • treeSitterPackage linked to 'tree-sitter-swift'
  • languageRegistration correctly passed from the local index

10-15: Test runner covers basic functionality

The test runner appropriately tests a basic Swift syntax pattern by:

  1. Parsing a simple println statement
  2. Verifying that the AST node is identified as a call_expression

This provides a good basic sanity check for the Swift parser integration.

@NatoBoram NatoBoram force-pushed the feature/swift branch 2 times, most recently from 09dca66 to 4f41a5a Compare April 4, 2025 21:01
@HerringtonDarkholme HerringtonDarkholme merged commit 07ddf41 into ast-grep:main Apr 5, 2025
3 checks passed
@NatoBoram NatoBoram deleted the feature/swift branch April 6, 2025 03:31
This was referenced 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