-
Notifications
You must be signed in to change notification settings - Fork 6
✨ 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
✨ Kotlin #55
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@ast-grep/lang-kotlin": patch | ||
--- | ||
|
||
Add @ast-grep/lang-kotlin |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# ast-grep napi language for kotlin | ||
|
||
## Installation | ||
|
||
In a pnpm project, run: | ||
|
||
```bash | ||
pnpm install @ast-grep/lang-kotlin | ||
pnpm install @ast-grep/napi | ||
# install the tree-sitter-cli if no prebuild is available | ||
pnpm install @tree-sitter/cli --save-dev | ||
``` | ||
|
||
## Usage | ||
|
||
```js | ||
import kotlin from '@ast-grep/lang-kotlin' | ||
import { registerDynamicLanguage, parse } from '@ast-grep/napi' | ||
|
||
registerDynamicLanguage({ kotlin }) | ||
|
||
const sg = parse('kotlin', `your code`) | ||
sg.root().kind() | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
type LanguageRegistration = { | ||
libraryPath: string | ||
extensions: string[] | ||
languageSymbol?: string | ||
metaVarChar?: string | ||
expandoChar?: string | ||
} | ||
|
||
declare const registration: LanguageRegistration | ||
export default registration |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const path = require('node:path') | ||
const libPath = path.join(__dirname, 'parser.so') | ||
|
||
module.exports = { | ||
libraryPath: libPath, | ||
extensions: ['kt', 'ktm', 'kts'], | ||
languageSymbol: 'tree_sitter_kotlin', | ||
expandoChar: 'µ', | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const { setup } = require('@ast-grep/nursery') | ||
const assert = require('node:assert') | ||
const languageRegistration = require('./index') | ||
|
||
setup({ | ||
dirname: __dirname, | ||
name: 'kotlin', | ||
treeSitterPackage: 'tree-sitter-kotlin', | ||
languageRegistration, | ||
testRunner: parse => { | ||
const sg = parse('println(123)') | ||
const root = sg.root() | ||
const node = root.find('println($A)') | ||
assert.equal(node.kind(), 'call_expression') | ||
}, | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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"] | ||
} | ||
} | ||
Comment on lines
+1
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainMissing index.js and other referenced files. The package.json references several important files that weren't included in this review:
🏁 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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
const { postinstall } = require('@ast-grep/setup-lang') | ||
postinstall({ | ||
dirname: __dirname, | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
🛠️ 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:Expand the test suite to cover more Kotlin syntax patterns to ensure the parser is robust across various language features.