Search for the previous sibling of the node. TODO: C TreeSitter should support this natively, but not its Python bindings yet. Replace later.
(tree, node)
| 46 | |
| 47 | |
| 48 | def previous_sibling(tree, node): |
| 49 | """ |
| 50 | Search for the previous sibling of the node. |
| 51 | TODO: C TreeSitter should support this natively, but not its Python bindings yet. Replace later. |
| 52 | """ |
| 53 | to_visit = [tree.root_node] |
| 54 | while len(to_visit) > 0: |
| 55 | next_node = to_visit.pop() |
| 56 | for i, node_at_i in enumerate(next_node.children): |
| 57 | if nodes_are_equal(node, node_at_i): |
| 58 | if i > 0: |
| 59 | return next_node.children[i-1] |
| 60 | return None |
| 61 | else: |
| 62 | to_visit.extend(next_node.children) |
| 63 | return ValueError("Could not find node in tree.") |
| 64 | |
| 65 | |
| 66 | # if parent_node.type == 'variable_declarator': |
nothing calls this directly
no test coverage detected