-
Notifications
You must be signed in to change notification settings - Fork 6
✨ 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
✨ Scala #59
Conversation
WalkthroughThis pull request adds a new package, Changes
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
Possibly related PRs
Suggested reviewers
Poem
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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 documentationWhile the implementation follows the standard pattern for ast-grep language packages, consider:
- Adding error handling to gracefully manage potential failures during installation
- 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 documentationThe 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 registrationpackages/scala/nursery.js (1)
1-16
: Expand test coverage for more Scala constructsThe current test is minimal and only verifies parsing of a simple Scala value definition. Consider:
- Adding more tests for different Scala constructs (classes, traits, objects, pattern matching, etc.)
- Including error handling in the test runner
- 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
⛔ 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 goodThe 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 parserextensions
correctly lists common Scala file extensionslanguageSymbol
andexpandoChar
are properly definedThe 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:
- 1: https://eed3si9n.com/tree-sitter-scala-0.22.1
- 2: https://eed3si9n.com/tree-sitter-scala-0.21.0
- 3: https://socket.dev/pypi/package/tree-sitter-scala
- 4: https://github.com/tree-sitter/tree-sitter-scala/releases
- 5: https://en.wikipedia.org/wiki/Tree-sitter_(parser_generator)
- 6: https://packages.gentoo.org/packages/dev-libs/tree-sitter-scala/changelog
- 7: https://www.npmjs.com/package/tree-sitter-scala
- 8: https://pypi.org/project/tree-sitter-languages/
- 9: https://github.com/tree-sitter/tree-sitter-scala
- 10: https://tree-sitter.github.io
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.
"files": [ | ||
"index.js", | ||
"index.d.ts", | ||
"type.d.ts", | ||
"postinstall.js", | ||
"src", | ||
"prebuilds" | ||
], |
There was a problem hiding this comment.
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
orprebuilds
), - Or, if not automatically generated, explicitly add it to the
"files"
array inpackages/scala/package.json
(for example, by appending"parser.so"
).
Summary by CodeRabbit