node-tree-sitter icon indicating copy to clipboard operation
node-tree-sitter copied to clipboard

What is the equivalent of `ts_node_child_by_field_name` in this wrapper?

Open ahelwer opened this issue 3 years ago • 3 comments

How do I get a child of a node by its field name? I can use a cursor to walk the children and get their field names with cursor.currentFieldName but is there any other way to do it?

ahelwer avatar Feb 03 '22 18:02 ahelwer

I don't remember finding another way.

Am interested if there is one though!

sogaiu avatar Feb 04 '22 03:02 sogaiu

You may access field names using index or the dot operator:

>>> syntaxNode.fields
["body"]
>>> syntaxNode.body
<the body field>
>>> syntaxNode["body"]
<the body field>

Neppord avatar Feb 15 '22 19:02 Neppord

@Neppord it works. Thank you! Sadly it's not in tree-sitter.d.ts and there is no ts_node_child_by_field_name equivalent.

ris58h avatar Apr 04 '22 14:04 ris58h

Duplicate of #68

verhovsky avatar Oct 17 '22 22:10 verhovsky