fix(kotlin): walk a same-line property accessor too

Follow-up to cf582f4. `val url: String get() = build(host)` nests the accessor
UNDER the property_declaration, so the hook consumed it and everything the
getter body called vanished — the initializer walk deliberately skipped
`getter`/`setter` on the theory that they are declaration, not code. They are
code.

Measured on the Android project this arc is validated against: 16 such
properties, whose accessor bodies contributed nothing at all.

An accessor written on its OWN line parses as a SIBLING of the property, not a
child, so it stays out of reach here and keeps attributing to the enclosing
class exactly as before. That asymmetry is the grammar's, and closing it means
looking backwards from a sibling accessor to the preceding declaration —
separate change, separate risk.

Whole-project re-measure (110 Kotlin + 100 JS + 37 Go files, both arms of the
extractor): 0 genuinely lost edges, +142 edges. The 13 edges that changed
identity are 9 JS initializer calls moving off the file node onto their
declaring constant, and 4 Kotlin `run(…)` call sites that used to name-match a
JavaScript test helper in desktop/test/ and now match a Kotlin `run` override.
This commit is contained in:
danusha2345
2026-08-05 23:08:33 +03:00
parent a10a7fa6f7
commit 8b2e43613c
5 changed files with 54 additions and 16 deletions
+10 -8
View File
@@ -43,13 +43,15 @@ function extractKotlinReturnType(node: SyntaxNode, source: string): string | und
}
/**
* A property's RHS: the named child right after the `=` token, plus a
* `property_delegate` (`by lazy { … }`). Everything else a
* `property_declaration` can hold is a declaration, not code — modifiers, the
* `val`/`var` keyword, the name+type, an extension receiver's type and type
* parameters, and `getter`/`setter` — so it stays unwalked. (Go's #693 fix
* walks the `value` field for the same reason; tree-sitter-kotlin exposes no
* fields at all, hence the `=` anchor.)
* A property's CODE children: the named child right after the `=` token, a
* `property_delegate` (`by lazy { … }`), and an accessor the grammar nested
* under the declaration (`val x: Int get() = compute()` — written on ONE line;
* an accessor on its own line parses as a SIBLING of the property and is not
* reachable from here). What stays unwalked is the declaration itself —
* modifiers, the `val`/`var` keyword, the name+type, and an extension
* receiver's type and type parameters. (Go's #693 fix walks the `value` field
* for the same reason; tree-sitter-kotlin exposes no fields at all, hence the
* `=` anchor.)
*/
function kotlinPropertyInitializers(node: SyntaxNode): SyntaxNode[] {
const out: SyntaxNode[] = [];
@@ -64,7 +66,7 @@ function kotlinPropertyInitializers(node: SyntaxNode): SyntaxNode[] {
if (afterEq) {
out.push(c);
afterEq = false;
} else if (c.type === 'property_delegate') {
} else if (c.type === 'property_delegate' || c.type === 'getter' || c.type === 'setter') {
out.push(c);
}
}