fix: index single-line Kotlin objects - #1610
Conversation
|
@mjq2020 is attempting to deploy a commit to the shashankss1205's projects Team on Vercel. A member of the Team first needs to authorize it. |
Shashankss1205
left a comment
There was a problem hiding this comment.
Approving — verified, though it took me a detour to do it correctly, and the detour is worth recording.
My first attempt said this PR was a no-op, because on my local venv main already handled single-line objects. That was wrong: my venv had tree-sitter-language-pack 0.13.0, while pyproject.toml pins >=1.6,<2.0. The behaviour here is entirely grammar-version dependent.
On the version the project actually pins (1.14.3), the reported misparse reproduces exactly:
object A { fun x() = 1 } -> top-level node = infix_expression, object_declaration captures = []
object A { } -> top-level node = object_declaration, captures = ['A']
object A {\n fun x()\n} -> top-level node = object_declaration, captures = ['A']
So only the one-line-with-body form breaks, which is precisely what your infix_expression → (object_literal, simple_identifier, lambda_literal) shape match targets.
Re-running the comparison on grammar 1.14.3:
main: objects=[Empty, MultiLine] functions=[a→MultiLine, b→None, c→Plain]
#1610: objects=[Empty, OneLine, MultiLine] functions=[a→MultiLine, b→OneLine, c→Plain]
So it recovers both the missing Object node and the orphaned function's class_context — b was previously landing with no owner at all, which is the part that would quietly corrupt containment queries.
Guarding on the exact three-child shape and checking the first child's text is literally object is appropriately conservative — it won't misfire on genuine infix expressions.
tests/unit/parsers/test_kotlin_parser.py: 90 passed under grammar 1.14.3. Full unit suite: 1206 passed.
|
Approved above — the only thing blocking merge is that this is still marked as a draft. Mark it ready for review and I'll merge it straight away. (I'd rather you flip it than do it for you, in case you were still intending changes.) |
Summary
infix_expressionshape produced for a single-line named Kotlin objectRoot cause
The Kotlin tree-sitter grammar parses
object A { fun x() = 1 }differently from the equivalent multiline declaration: it emits aninfix_expressioncontainingobject_literal,simple_identifier, andlambda_literal, so the existingobject_declarationquery never sees the object. The parser still sees the nested function, but without its owning object context.Tests
TMPDIR=/private/tmp pytest -q tests/unit/parsers/test_kotlin_parser.py— 90 passedTMPDIR=/private/tmp ./tests/run_tests.sh fast— 1190 passed, 19 skipped before stopping slow unrelated golden cases; five existing failures were unrelated CLI inventory drift andbundle_exportreceiving a TyperOptionInfopython -m compileall -q src/codegraphcontext/tools/languages/kotlin.py tests/unit/parsers/test_kotlin_parser.pygit diff --checkFixes #1600