tree-sitter / node-tree-sitter

Node.js bindings for tree-sitter
https://www.npmjs.com/package/tree-sitter
MIT License
649 stars 114 forks source link

feat: add childNodeForFieldName #100

Closed paf31 closed 1 year ago

paf31 commented 2 years ago

This adds a wrapper for the ts_node_child_by_field_name function directly (c.f. #99) . I realized, as I was working on this, that it is already possible to use the generated property getters, which go via field IDs, but in any case, this might be useful as it brings the API closer to parity with web-tree-sitter (#68)

My C++ is extremely rusty (no pun intended) so I'm happy to take any pointers on style etc. there, but I mostly followed the examples in the other functions.

I added a minimal test case, but I could add additional test cases if we agree this is useful.

Thanks!

paf31 commented 2 years ago

I'm not sure why the tests are failing on x86 only - if someone could give me a pointer, I'd be glad to fix it.

ris58h commented 1 year ago

@maxbrunsfeld could you take a look? UPDATE: Should we use property access instead?