diff options
author | Michael Davis | 2022-11-17 01:03:02 +0000 |
---|---|---|
committer | GitHub | 2022-11-17 01:03:02 +0000 |
commit | 94346356e7657011adf0012651ec031b98d87411 (patch) | |
tree | 694dd8d0cb604facf011b890ba482e7f802ed78b /languages.toml | |
parent | c6b83368b3b626cb63120b5ac684cc8b1b693172 (diff) |
Use TreeCursor to pretty-print :tree-sitter-subtree (#4606)
The current `:tree-sitter-subtree` has a bug for field-names when the
field name belongs to an unnamed child node. Take this ruby example:
def self.method_name
true
end
The subtree given by tree-sitter-cli is:
(singleton_method [2, 0] - [4, 3]
object: (self [2, 4] - [2, 8])
name: (identifier [2, 9] - [2, 20])
body: (body_statement [3, 2] - [3, 6]
(true [3, 2] - [3, 6])))
But the `:tree-sitter-subtree` output was
(singleton_method
object: (self)
body: (identifier)
(body_statement (true)))
The `singleton_method` rule defines the `name` and `body` fields in an
unnamed helper rule `_method_rest` and the old implementation of
`pretty_print_tree_impl` would pass the `field_name` down from the
named `singleton_method` node.
To fix it we switch to the [TreeCursor] API which is recommended by
the tree-sitter docs for traversing the tree. `TreeCursor::field_name`
accurately determines the field name for the current cursor position
even when the node is unnamed.
[TreeCursor]: https://docs.rs/tree-sitter/0.20.9/tree_sitter/struct.TreeCursor.html
Diffstat (limited to 'languages.toml')
0 files changed, 0 insertions, 0 deletions