diff options
author | Gregory Anders <8965202+gpanders@users.noreply.github.com> | 2023-11-30 07:04:20 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-30 07:04:20 -0600 |
commit | 01b91deec7b6113ae728ac3f7a55f64f57ddb3e0 (patch) | |
tree | faf0960f3dac2574665d30c5829fdff058f8b263 /runtime/lua/vim/re.lua | |
parent | 52d738826cc091099ca6b25f718b9ca36d7b4b4e (diff) | |
download | rneovim-01b91deec7b6113ae728ac3f7a55f64f57ddb3e0.tar.gz rneovim-01b91deec7b6113ae728ac3f7a55f64f57ddb3e0.tar.bz2 rneovim-01b91deec7b6113ae728ac3f7a55f64f57ddb3e0.zip |
fix(treesitter): fix parens stacking in inspector display (#26304)
When first opened, the tree-sitter inspector traverses all of the nodes
in the buffer to calculate an array of nodes. This traversal is done
only once, and _all_ nodes (both named and anonymous) are included.
Toggling anonymous nodes in the inspector only changes how the tree is
drawn in the buffer, but does not affect the underlying data structure
at all.
When the buffer is traversed and the list of nodes is calculated, we
don't know whether or not anonymous nodes will be displayed in the
inspector or not. Thus, we cannot determine during traversal where to
put closing parentheses. Instead, this must be done when drawing.
When we draw, the tree structure has been flatted into a single array,
so we lose parent-child relationships that would otherwise make
determining the number of closing parentheses straightforward. However,
we can instead rely on the fact that a delta between the depth of a node
and the depth of the successive node _must_ mean that more closing
parentheses are required:
(foo
(bar)
(baz) ↑
│
└ (bar) and (baz) have different depths, so (bar) must have an
extra closing parenthesis
This does not depend on whether or not anonymous nodes are displayed and
so works in both cases.
Diffstat (limited to 'runtime/lua/vim/re.lua')
0 files changed, 0 insertions, 0 deletions