Commit ef0a092
committed
Use TreeCursor to pretty-print :tree-sitter-subtree
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.html1 parent 3814987 commit ef0a092
1 file changed
Lines changed: 71 additions & 30 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1260 | 1260 | | |
1261 | 1261 | | |
1262 | 1262 | | |
1263 | | - | |
| 1263 | + | |
1264 | 1264 | | |
1265 | 1265 | | |
1266 | 1266 | | |
| |||
2130 | 2130 | | |
2131 | 2131 | | |
2132 | 2132 | | |
| 2133 | + | |
| 2134 | + | |
| 2135 | + | |
| 2136 | + | |
2133 | 2137 | | |
2134 | | - | |
| 2138 | + | |
| 2139 | + | |
| 2140 | + | |
| 2141 | + | |
| 2142 | + | |
| 2143 | + | |
| 2144 | + | |
| 2145 | + | |
| 2146 | + | |
2135 | 2147 | | |
2136 | 2148 | | |
2137 | 2149 | | |
2138 | 2150 | | |
2139 | | - | |
2140 | | - | |
2141 | | - | |
| 2151 | + | |
2142 | 2152 | | |
2143 | 2153 | | |
2144 | | - | |
2145 | | - | |
2146 | | - | |
2147 | | - | |
| 2154 | + | |
| 2155 | + | |
2148 | 2156 | | |
2149 | | - | |
| 2157 | + | |
2150 | 2158 | | |
2151 | 2159 | | |
2152 | 2160 | | |
2153 | | - | |
| 2161 | + | |
2154 | 2162 | | |
2155 | 2163 | | |
2156 | 2164 | | |
2157 | 2165 | | |
2158 | | - | |
2159 | | - | |
2160 | 2166 | | |
2161 | 2167 | | |
2162 | | - | |
2163 | | - | |
2164 | | - | |
| 2168 | + | |
| 2169 | + | |
| 2170 | + | |
| 2171 | + | |
2165 | 2172 | | |
2166 | 2173 | | |
2167 | 2174 | | |
2168 | | - | |
2169 | | - | |
2170 | | - | |
2171 | | - | |
2172 | | - | |
2173 | | - | |
2174 | | - | |
| 2175 | + | |
| 2176 | + | |
| 2177 | + | |
| 2178 | + | |
| 2179 | + | |
2175 | 2180 | | |
| 2181 | + | |
| 2182 | + | |
| 2183 | + | |
| 2184 | + | |
| 2185 | + | |
2176 | 2186 | | |
2177 | 2187 | | |
2178 | | - | |
2179 | | - | |
| 2188 | + | |
| 2189 | + | |
2180 | 2190 | | |
2181 | 2191 | | |
2182 | 2192 | | |
2183 | 2193 | | |
| 2194 | + | |
2184 | 2195 | | |
2185 | 2196 | | |
2186 | 2197 | | |
| |||
2353 | 2364 | | |
2354 | 2365 | | |
2355 | 2366 | | |
2356 | | - | |
| 2367 | + | |
| 2368 | + | |
| 2369 | + | |
| 2370 | + | |
| 2371 | + | |
| 2372 | + | |
| 2373 | + | |
2357 | 2374 | | |
2358 | 2375 | | |
2359 | 2376 | | |
2360 | | - | |
| 2377 | + | |
2361 | 2378 | | |
2362 | 2379 | | |
2363 | 2380 | | |
| |||
2377 | 2394 | | |
2378 | 2395 | | |
2379 | 2396 | | |
2380 | | - | |
| 2397 | + | |
2381 | 2398 | | |
2382 | 2399 | | |
2383 | 2400 | | |
2384 | 2401 | | |
2385 | 2402 | | |
2386 | 2403 | | |
| 2404 | + | |
2387 | 2405 | | |
2388 | 2406 | | |
2389 | 2407 | | |
| |||
2402 | 2420 | | |
2403 | 2421 | | |
2404 | 2422 | | |
2405 | | - | |
| 2423 | + | |
2406 | 2424 | | |
2407 | 2425 | | |
2408 | 2426 | | |
2409 | | - | |
| 2427 | + | |
| 2428 | + | |
| 2429 | + | |
| 2430 | + | |
| 2431 | + | |
| 2432 | + | |
| 2433 | + | |
| 2434 | + | |
| 2435 | + | |
| 2436 | + | |
| 2437 | + | |
| 2438 | + | |
| 2439 | + | |
| 2440 | + | |
| 2441 | + | |
| 2442 | + | |
| 2443 | + | |
| 2444 | + | |
| 2445 | + | |
| 2446 | + | |
| 2447 | + | |
| 2448 | + | |
| 2449 | + | |
| 2450 | + | |
2410 | 2451 | | |
2411 | 2452 | | |
2412 | 2453 | | |
| |||
0 commit comments