MCPcopy Index your code
hub / github.com/FSoft-AI4Code/CodeText-parser / get_node_by_kind

Function get_node_by_kind

src/codetext/parser/language_parser.py:123–140  ·  view source on GitHub ↗

Get all nodes with specific type Args: root (tree_sitter.Node): Tree sitter root node kind (List[str]): (node's) type that want to get Return: List[tree_sitter.Node]: List of all

(root: tree_sitter.Node, kind: List[str])

Source from the content-addressed store, hash-verified

121
122
123def get_node_by_kind(root: tree_sitter.Node, kind: List[str]) -> List:
124 """
125 Get all nodes with specific type
126
127 Args:
128 root (tree_sitter.Node): Tree sitter root node
129 kind (List[str]): (node's) type that want to get
130
131 Return:
132 List[tree_sitter.Node]: List of all
133 """
134 assert type(root) == tree_sitter.Node, f"Expect `root` to be `tree_sitter.Node`, get {type(root)}"
135 assert type(kind) in [list, str], f"Expect `kind` to be `list` of string or `str`, get {type(kind)}"
136 assert all(isinstance(s, str) for s in kind) == True, f"Expect search kind to be `str`"
137
138 node_list = []
139 traverse_type(root, node_list, kind=kind)
140 return node_list
141
142
143def get_node_text(root: tree_sitter.Node) -> str:

Callers 15

get_comment_nodeMethod · 0.85
get_function_listMethod · 0.85
get_class_listMethod · 0.85
get_function_metadataMethod · 0.85
get_comment_nodeMethod · 0.85
get_class_listMethod · 0.85
get_function_listMethod · 0.85
get_function_metadataMethod · 0.85
get_function_listMethod · 0.85
get_class_listMethod · 0.85
get_comment_nodeMethod · 0.85
get_function_metadataMethod · 0.85

Calls 1

traverse_typeFunction · 0.85

Tested by

no test coverage detected