Skip to content

✨ Scala #59

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

✨ Scala #59

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 Scala language support with dynamic language registration and code parsing capabilities.
  • Documentation
    • Added detailed installation instructions and usage examples to help integrate Scala support into your projects.
  • Tests
    • Implemented a test framework to ensure robust Scala code parsing.
  • Chores
    • Optimized post-installation processes for a seamless integration experience.

Copy link

coderabbitai bot commented Apr 3, 2025

Walkthrough

This pull request adds a new package, @ast-grep/lang-scala, to provide Scala language support. It introduces documentation, API definitions, testing setup, and build configurations. Changes include the addition of a changeset entry, a README with installation and usage instructions, type definitions and exports for language registration, tests for syntax tree parsing, a package manifest, and a post-installation script that triggers setup procedures.

Changes

Files Change Summary
.changeset/tired-comics-hear.md Added a changeset entry indicating the addition of the @ast-grep/lang-scala package.
packages/scala/README.md Introduced a new README with installation instructions, usage examples, and integration details for Scala language support and the related @ast-grep/napi package.
packages/scala/index.d.ts
packages/scala/index.js
Added new type definitions and module exports for Scala language configuration, including properties for library path, extensions, language symbol, and expando character.
packages/scala/nursery.js Created a test setup file that uses @ast-grep/nursery to verify Scala syntax tree parsing with a sample Scala expression.
packages/scala/package.json Added a package manifest for @ast-grep/lang-scala with version information, scripts for building and testing, dependencies, and publication configuration.
packages/scala/postinstall.js Introduced a post-install script that calls the setup function from @ast-grep/setup-lang using the current directory, assisting in post-installation tasks related to the Scala package.

Sequence Diagram(s)

sequenceDiagram
    participant Dev as Developer
    participant PI as PostInstall
    participant SU as @ast-grep/setup-lang
    participant LX as Scala Module
    participant TS as Tree-sitter Parser

    Dev->>PI: Run postinstall procedure
    PI->>SU: Call postinstall({ dirname: __dirname })
    SU->>LX: Initialize Scala language configuration
    Dev->>LX: Invoke registerDynamicLanguage({ scala })
    Dev->>LX: Call parse('scala', code)
    LX->>TS: Forward code for AST parsing
    TS-->>LX: Return syntax tree
Loading

Possibly related PRs

  • feat: C# language #41: Introduced the @ast-grep/lang-csharp package with similar structure and functionality to the Scala package.
  • ✨ Bash #46: Added the @ast-grep/lang-bash package, sharing the approach for language support integrations.
  • ✨ Dart #48: Brought in the @ast-grep/lang-dart package, aligning with the new package structure and testing setup.

Suggested reviewers

  • HerringtonDarkholme

Poem

I'm a rabbit with a happy beat,
Coding Scala support is oh-so-sweet!
New files hop in, one by one,
Parsing code and having fun!
With a twitch of my nose, I cheer today 🐇✨
CodeRabbit bounds into a brighter way!
Hop on, and let's play!

✨ Finishing Touches
  • 📝 Generate Docstrings

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: 1

🧹 Nitpick comments (5)
packages/scala/postinstall.js (1)

1-4: Consider adding error handling and documentation

While the implementation follows the standard pattern for ast-grep language packages, consider:

  1. Adding error handling to gracefully manage potential failures during installation
  2. Including comments to explain what the postinstall function does for future maintainers
const { postinstall } = require('@ast-grep/setup-lang')
- postinstall({
-   dirname: __dirname,
- })
+ // Run post-installation tasks for Scala language support
+ try {
+   postinstall({
+     dirname: __dirname,
+   })
+ } catch (error) {
+   console.error('Failed to complete Scala language setup:', error.message)
+   // Decide if you want to exit with an error code or continue
+ }
packages/scala/index.d.ts (1)

1-10: Add JSDoc comments for better documentation

The type definition is well-structured, but would benefit from JSDoc comments to improve code readability and provide better IDE tooltips:

+ /**
+  * Interface for registering a language with ast-grep
+  */
type LanguageRegistration = {
+  /** Path to the language library */
  libraryPath: string
+  /** File extensions associated with this language */
  extensions: string[]
+  /** Optional symbol for identifying the language */
  languageSymbol?: string
+  /** Optional character used for meta-variables in patterns */
  metaVarChar?: string
+  /** Optional character used for expando-variables in patterns */
  expandoChar?: string
}

+ /**
+  * Registration object for Scala language support
+  */
declare const registration: LanguageRegistration
export default registration
packages/scala/nursery.js (1)

1-16: Expand test coverage for more Scala constructs

The current test is minimal and only verifies parsing of a simple Scala value definition. Consider:

  1. Adding more tests for different Scala constructs (classes, traits, objects, pattern matching, etc.)
  2. Including error handling in the test runner
  3. Making tests more resilient to implementation changes
setup({
  dirname: __dirname,
  name: 'scala',
  treeSitterPackage: 'tree-sitter-scala',
  languageRegistration,
  testRunner: parse => {
+   try {
      const sg = parse('val a = 0')
      const root = sg.root()
      const node = root.find('val $A = 0')
      assert.equal(node.kind(), 'val_definition')
+     
+     // Test for a class definition
+     const classSg = parse('class Example { val x = 1 }')
+     const classRoot = classSg.root()
+     const classNode = classRoot.find('class $Name { $Body }')
+     assert.equal(classNode.kind(), 'class_definition')
+     
+     // Test for a method definition
+     const methodSg = parse('def add(a: Int, b: Int): Int = a + b')
+     const methodRoot = methodSg.root()
+     const methodNode = methodRoot.find('def $Name($Params): $ReturnType = $Body')
+     assert.equal(methodNode.kind(), 'function_definition')
+   } catch (error) {
+     console.error('Test failed:', error.message)
+     throw error
+   }
  },
})
packages/scala/package.json (2)

4-4: Add a meaningful description for the package.

The description field is currently empty. Consider adding a brief description such as "Tree-sitter based Scala language support for ast-grep" to help users understand the package's purpose.

-  "description": "",
+  "description": "Tree-sitter based Scala language support for ast-grep",

22-22: Add author information.

The author field is currently empty. Consider adding the author's name or the organization's name to provide proper attribution.

-  "author": "",
+  "author": "NatoBoram",
📜 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 dbcd91f.

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

1-6: Changeset format looks good

The changeset entry correctly specifies a patch version bump for the new @ast-grep/lang-scala package with a clear commit message.

packages/scala/README.md (1)

1-25: LGTM! Clear and concise README for the Scala language package.

The README provides all the essential information for users:

  • Installation instructions with clear steps for a pnpm project
  • Proper usage examples showing how to register the language and parse Scala code
  • Good code samples that demonstrate the API

The documentation covers everything needed to get started with the package.

packages/scala/index.js (1)

1-9: LGTM! The index.js file correctly exports the Scala language configuration.

The module exports all the necessary properties for the AST-grep language integration:

  • libraryPath points to the compiled parser
  • extensions correctly lists common Scala file extensions
  • languageSymbol and expandoChar are properly defined

The implementation follows the standard pattern for ast-grep language packages.

packages/scala/package.json (2)

1-47: LGTM for the overall package.json structure.

The package.json follows the standard structure and includes all the necessary configurations:

  • Proper scripts for building, testing, and installation
  • Correct dependencies with appropriate versioning
  • Good publishing configuration

With the minor suggestions above, this looks ready to go.


35-39:

✅ Verification successful

Verify tree-sitter-scala version matches the expected version.

Make sure the tree-sitter-scala version in devDependencies (0.23.4) is the latest stable version that works with your build setup. You might want to check if there are newer versions available.


🌐 Web query:

What is the latest version of tree-sitter-scala?

💡 Result:

The latest version of tree-sitter-scala is 0.23.4, released on December 26, 2024[4][7][9]. This version includes updates such as:

  • Support for SIP-47 Clause Interleaving
  • Named tuple support (SIP-58)
  • Polymorphic function types and lambda expressions
  • Dependency updates to tree-sitter 0.23.0[4]

The parser is published on multiple platforms including:

  • NPM: Available as version 0.23.4[7]
  • crates.io: Rust bindings[4]
  • PyPI: Through the tree-sitter-languages package[3][8]

Recent versions have shown significant parsing improvements, achieving 100% success on Scala 2 libraries, 96% on Scala 2 compilers, and 85% on Scala 3 compilers[2]. The project maintains active development with contributions from multiple maintainers and regular updates to support modern Scala features[1][4][9].

Citations:


Dependency Versions Verified: tree-sitter-scala is up-to-date!

The version of tree-sitter-scala in the packages/scala/package.json devDependencies (0.23.4) has been confirmed to be the latest stable release. No updates are necessary.

Comment on lines +13 to +20
"files": [
"index.js",
"index.d.ts",
"type.d.ts",
"postinstall.js",
"src",
"prebuilds"
],
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

Confirm all necessary files are included in the package.

The files array includes index.js, type definitions, and postinstall.js, but there's no reference to parser.so which is used in index.js. Make sure this file gets included either through the build process or by adding it explicitly to the files array.


🏁 Script executed:

#!/bin/bash
# Check if parser.so gets created during build and where it's located
ls -la packages/scala/

Length of output: 507


Action Required: Ensure parser.so is Included in the Package

The parser.so file referenced in index.js was not found in the package directory output. Please verify that:

  • It is generated by the build process and placed within an included folder (e.g., inside src or prebuilds),
  • Or, if not automatically generated, explicitly add it to the "files" array in packages/scala/package.json (for example, by appending "parser.so").

@HerringtonDarkholme HerringtonDarkholme merged commit 1f986c8 into ast-grep:main Apr 5, 2025
3 checks passed
@NatoBoram NatoBoram deleted the feature/scala branch April 5, 2025 06:36
@coderabbitai coderabbitai bot mentioned this pull request 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