How to get the tree structure data of class/property/method in tree-sitter:
I can only match the class like below:
const Parser = require("tree-sitter")
const JavaScript = require("tree-sitter-javascript")
const { Query } = Parser
const parser = new Parser()
parser.setLanguage(JavaScript)
const query = new Query(
JavaScript,
`
(class_declaration name: (identifier) @class-name)
`
);
const tree = parser.parse(`
class Person {}
const TestPerson = class {}
class Person2 {}
const TestPerson2 = class {}
`);
const matches = query.matches(tree.rootNode);
matches.forEach(item => {
console.log(item.captures[0])
})
there I can get the classnames of a file.
but you see the GitHub page: I want to get the tree structure data of AST:
1、please help with how to match the AST tree data?
2、you see the snapshot display a 3-layer depth tree data, how to control the matched tree data depth?