Skip to content

Commit f932ff8

Browse files
fix: go to first child in Node.children
1 parent 99a7356 commit f932ff8

File tree

4 files changed

+4
-2
lines changed
  • ktreesitter/src
    • androidInstrumentedTest/kotlin/io/github/treesitter/ktreesitter
    • commonTest/kotlin/io/github/treesitter/ktreesitter
    • jni
    • nativeMain/kotlin/io/github/treesitter/ktreesitter

4 files changed

+4
-2
lines changed

ktreesitter/src/androidInstrumentedTest/kotlin/io/github/treesitter/ktreesitter/NodeTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class NodeTest : FunSpec({
129129

130130
test("children") {
131131
val children = rootNode.children
132-
children.forSingle { it.type shouldBe "program" }
132+
children.forSingle { it.type shouldBe "class_declaration" }
133133
rootNode.children shouldBeSameInstanceAs children
134134
}
135135

ktreesitter/src/commonTest/kotlin/io/github/treesitter/ktreesitter/NodeTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class NodeTest : FunSpec({
126126

127127
test("children") {
128128
val children = rootNode.children
129-
children.forSingle { it.type shouldBe "program" }
129+
children.forSingle { it.type shouldBe "class_declaration" }
130130
rootNode.children shouldBeSameInstanceAs children
131131
}
132132

ktreesitter/src/jni/node.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ jobject JNICALL node_get_children(JNIEnv *env, jobject this) {
155155

156156
jobject tree = GET_FIELD(Object, this, Node_tree);
157157
TSTreeCursor cursor = ts_tree_cursor_new(self);
158+
(void)ts_tree_cursor_goto_first_child(&cursor);
158159
for (uint32_t i = 0; i < count; ++i) {
159160
TSNode ts_node = ts_tree_cursor_current_node(&cursor);
160161
jobject node_obj = marshal_node(env, ts_node, tree);

ktreesitter/src/nativeMain/kotlin/io/github/treesitter/ktreesitter/Node.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ actual class Node internal constructor(
164164
val length = childCount.toInt()
165165
if (length == 0) return emptyList()
166166
val cursor = ts_tree_cursor_new(self).ptr
167+
ts_tree_cursor_goto_first_child(cursor)
167168
internalChildren = List(length) {
168169
val node = ts_tree_cursor_current_node(cursor)
169170
ts_tree_cursor_goto_next_sibling(cursor)

0 commit comments

Comments
 (0)