how to get function name or variable name from tree

I want to get the structure of the code, like the function name, the type of args and so on. Is there any ways I can do that?

thanks.

Syntax node content (such as names) is not stored in the tree, but you can use the position of the node to read it from the document. Types of things are only available insofar as they are directly encoded in the syntax—this library does not do type inference or anything like that.

To get the function name or variable name from a tree, you need to traverse the tree and extract the information you need from the relevant nodes.

Here are some general steps you can follow:

  1. Determine the type of the node you’re looking at. Is it a function call node, a variable node, or something else?
  2. If the node is a function call node, extract the function name from the node. This can typically be found in the “value” or “id” attribute of the node.
  3. If the node is a variable node, extract the variable name from the node. This can typically be found in the “id” attribute of the node.
  4. Traverse the tree recursively, examining each child node of the current node until you find the node(s) that contain the information you need.
  5. If you need to get information about a specific function or variable, you may need to use additional information, such as the context in which the tree is being used, to determine which node(s) correspond to that function or variable.

Note that the specific implementation details of how to traverse the tree and extract the relevant information will depend on the language and tooling you are using.
Ragards : Namesolutions