tree-sitter / node-tree-sitter

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

[question] How to query out the classes and funcs from source code? #213

Closed liaodalin19903 closed 2 months ago

liaodalin19903 commented 3 months ago

Hi,

I know GitHub uses tree-sitter to query out the classes and funcs :

image

but in tree-sitter I don't find a way to do it, is there any API to implment it? is there any higher level wrapper lib?

segevfiner commented 3 months ago

You use Parser.Query passing it the language and tree-sitter query string and then use its methods to look at the results. Documentation is missing for this ATM, but you can check out https://github.com/tree-sitter/node-tree-sitter/blob/master/test/query_test.js.