If the source contains very long else if chain, and a query pattern has a (editor-specific) predicate that climbs up the tree, processing the predicate can be very slow. For example, Neovim's #has-ancestor? predicate can be slow: https://github.com/neovim/neovim/issues/24965.
Naively folding each (if_statement) would create a nested fold for each else if, resulting in deeply nested folds. What user would want is to have fold for each body of else if.
Describe the solution you'd like
The entire if-else if-else should be parsed as flat list. Something like this:
(if_statement
(alternative (condition) (consequence)) ; the first `if`
(alternative (condition) (consequence)) ; the first `else if`
(alternative (condition) (consequence)) ; the second `else if`
...
(else (consequence)) ; `else`
)
Did you check the tree-sitter docs?
Is your feature request related to a problem? Please describe.
Currently,
else if
blocks are parsed as nestedif
statements. For example,This structure is suboptimal for various reasons.
If the source contains very long
else if
chain, and a query pattern has a (editor-specific) predicate that climbs up the tree, processing the predicate can be very slow. For example, Neovim's#has-ancestor?
predicate can be slow: https://github.com/neovim/neovim/issues/24965.Naively folding each
(if_statement)
would create a nested fold for eachelse if
, resulting in deeply nested folds. What user would want is to have fold for each body ofelse if
.Describe the solution you'd like
The entire
if
-else if
-else
should be parsed as flat list. Something like this:Describe alternatives you've considered
consequence: (compound_statement)
instead ofif_statement
.Additional context
No response