Skip to content

✨ Kotlin #55

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

Conversation

NatoBoram
Copy link
Collaborator

@NatoBoram NatoBoram commented Apr 2, 2025

Halfway there!

Summary by CodeRabbit

  • New Features

    • Introduced comprehensive Kotlin language support, enabling seamless parsing and integration for Kotlin code.
    • Enhanced language registration to ensure smooth interoperability with existing tooling.
  • Documentation

    • Added detailed installation instructions and usage examples to help users easily integrate the new Kotlin support into their projects.

Copy link

coderabbitai bot commented Apr 2, 2025

Walkthrough

This pull request adds Kotlin language support by introducing a new package, @ast-grep/lang-kotlin. The changes encompass new documentation, type definitions, core language configuration, a testing environment setup, package configuration, and a post-installation script. These updates establish the foundation for parsing and handling Kotlin source code within the project.

Changes

File(s) Change Summary
.changeset/khaki-badgers-hammer.md Added a new patch entry to include the @ast-grep/lang-kotlin package, signaling the introduction of Kotlin language support.
packages/kotlin/{README.md, index.d.ts, index.js, nursery.js, package.json, postinstall.js} Introduced a new Kotlin support package: provided installation instructions in README, defined the LanguageRegistration type and configuration in index files, set up a testing script, added package configuration, and included a post-install script.

Possibly related PRs

  • ✨ Rust #58: The changes in the main PR, which introduce Kotlin language support, are related to the retrieved PR that adds Rust language support, as both involve the addition of new language packages (@ast-grep/lang-kotlin and @ast-grep/lang-rust) and similar structures in their respective files.
  • ✨ Swift #60: The changes in the main PR, which introduce the @ast-grep/lang-kotlin package, are related to the changes in the retrieved PR that introduce the @ast-grep/lang-swift package, as both involve the addition of new language support packages with similar structures and functionalities.

Suggested reviewers

  • HerringtonDarkholme

Poem

I'm a rabbit with hops so bold,
Chasing new code treasures untold.
Kotlin support now makes my day bright,
Parsing lines with pure delight.
Hop along in this patchy spree,
With nibbling code, I code with glee!
🐇✨


📜 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 ed988d1 and bcae3b8.

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

🪧 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/kotlin branch 2 times, most recently from 4bbb114 to e4551ad 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: 2

🧹 Nitpick comments (6)
packages/kotlin/index.js (1)

1-9: Consider adding the metaVarChar property for consistency with type definition.

The implementation exports the necessary properties for Kotlin language support, but doesn't include metaVarChar which is defined in the LanguageRegistration type. While it's marked as optional in the type, you might want to include it for consistency if Kotlin has a specific meta-variable character.

module.exports = {
  libraryPath: libPath,
  extensions: ['kt', 'ktm', 'kts'],
  languageSymbol: 'tree_sitter_kotlin',
+ metaVarChar: '$', // Add the appropriate meta-variable character for Kotlin
  expandoChar: 'µ',
}
packages/kotlin/README.md (1)

1-24: Good documentation start, but could be more comprehensive.

The README provides basic installation and usage instructions for the Kotlin language support, which is helpful. However, it would benefit from additional information such as:

  1. Brief explanation of what ast-grep is and what this Kotlin package specifically enables
  2. Installation instructions for npm and yarn users (not just pnpm)
  3. Examples of actual Kotlin code patterns that can be recognized/parsed
  4. Information about supported Kotlin syntax features or limitations

Consider expanding the documentation to make it more accessible to users who might be unfamiliar with ast-grep or Kotlin integration.

packages/kotlin/nursery.js (1)

1-3: Consider module consistency between code and documentation.

The nursery.js file uses CommonJS module syntax (require), while the README example uses ESM import statements. This inconsistency might confuse users.

Consider aligning the module system used in the tests with what's shown in the documentation, or note in the README if both module systems are supported.

packages/kotlin/package.json (3)

4-4: Add a meaningful package description.

The description field is empty. Adding a clear description would help users understand the purpose of this package when viewing it on npm.

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

22-22: Add author information.

The author field is empty. Including author information helps with package attribution and provides a point of contact.

- "author": "",
+ "author": "NatoBoram",

45-45: Recursive dependency in onlyBuiltDependencies.

The onlyBuiltDependencies array includes "@ast-grep/lang-kotlin", which is recursive since this is the package itself.

- "onlyBuiltDependencies": ["@ast-grep/lang-kotlin", "tree-sitter-cli"]
+ "onlyBuiltDependencies": ["tree-sitter-cli"]
📜 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 e4551ad.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (7)
  • .changeset/khaki-badgers-hammer.md (1 hunks)
  • packages/kotlin/README.md (1 hunks)
  • packages/kotlin/index.d.ts (1 hunks)
  • packages/kotlin/index.js (1 hunks)
  • packages/kotlin/nursery.js (1 hunks)
  • packages/kotlin/package.json (1 hunks)
  • packages/kotlin/postinstall.js (1 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
packages/kotlin/postinstall.js (1)
packages/kotlin/nursery.js (1)
  • require (1-1)
🔇 Additional comments (4)
.changeset/khaki-badgers-hammer.md (1)

1-6: LGTM! Changeset file correctly declares the new package.

The file properly indicates the addition of the @ast-grep/lang-kotlin package with a patch version bump, following the project's changeset conventions.

packages/kotlin/postinstall.js (1)

1-4: LGTM! Post-installation script follows project conventions.

The script correctly imports the postinstall function from the @ast-grep/setup-lang package and invokes it with the current directory, consistent with other language packages in the project.

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

1-10: LGTM! Type definitions are well-structured.

The LanguageRegistration type correctly defines all the necessary properties for Kotlin language support, and the default export is properly declared.

packages/kotlin/package.json (1)

10-10:

✅ Verification successful

Verify the existence of postinstall.js.

The package.json references a postinstall.js file in both the scripts and files sections, but this file wasn't included in the files for review.


🏁 Script executed:

#!/bin/bash
# Check if postinstall.js exists in the repository
fd --type file postinstall.js

Length of output: 412


Resolved: Verified that postinstall.js exists in packages/kotlin

The file referenced in packages/kotlin/package.json is indeed present (located at packages/kotlin/postinstall.js). No further action is needed.

Comment on lines +10 to +15
testRunner: parse => {
const sg = parse('println(123)')
const root = sg.root()
const node = root.find('println($A)')
assert.equal(node.kind(), 'call_expression')
},
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Test coverage is minimal.

The test only verifies a simple println(123) statement. While this is a good starting point, it would be more robust to test additional Kotlin language constructs like:

  • Class and function declarations
  • Control flow structures (if/else, loops)
  • Lambda expressions
  • Type declarations and generics
  • String interpolation

Expand the test suite to cover more Kotlin syntax patterns to ensure the parser is robust across various language features.

Comment on lines +1 to +47
{
"name": "@ast-grep/lang-kotlin",
"version": "0.0.1",
"description": "",
"main": "index.js",
"scripts": {
"build": "tree-sitter build -o parser.so",
"source": "node nursery.js source",
"prepublishOnly": "node nursery.js source",
"postinstall": "node postinstall.js",
"test": "node nursery.js test"
},
"files": [
"index.js",
"index.d.ts",
"type.d.ts",
"postinstall.js",
"src",
"prebuilds"
],
"keywords": ["ast-grep"],
"author": "",
"license": "ISC",
"dependencies": {
"@ast-grep/setup-lang": "0.0.3"
},
"peerDependencies": {
"tree-sitter-cli": "0.24.6"
},
"peerDependenciesMeta": {
"tree-sitter-cli": {
"optional": true
}
},
"devDependencies": {
"@ast-grep/nursery": "0.0.2",
"tree-sitter-cli": "0.24.6",
"tree-sitter-kotlin": "0.3.8"
},
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org/"
},
"pnpm": {
"onlyBuiltDependencies": ["@ast-grep/lang-kotlin", "tree-sitter-cli"]
}
}
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Missing index.js and other referenced files.

The package.json references several important files that weren't included in this review:

  • index.js (main entry point)
  • index.d.ts (TypeScript definitions)
  • type.d.ts
  • postinstall.js

🏁 Script executed:

#!/bin/bash
# Check for the existence of important files
echo "Checking for required files in the packages/kotlin directory:"
for file in index.js index.d.ts type.d.ts postinstall.js
do
  if [ -f "packages/kotlin/$file" ]; then
    echo "$file exists"
  else
    echo "$file is missing"
  fi
done

Length of output: 735


Action Required: Missing File Discrepancy in Package

After verification, only type.d.ts is missing, while index.js, index.d.ts, and postinstall.js are all present. Please add the missing type.d.ts file to the packages/kotlin directory, or update the files field in package.json if this file is not needed.

@NatoBoram NatoBoram force-pushed the feature/kotlin branch 2 times, most recently from f5694e6 to ed988d1 Compare April 6, 2025 03:28
@HerringtonDarkholme HerringtonDarkholme merged commit f79dcd8 into ast-grep:main Apr 6, 2025
3 checks passed
@NatoBoram NatoBoram deleted the feature/kotlin branch April 6, 2025 05:17
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