Subject: Re: bug#59633: 29.0.50; tree-sitter-bash: Incorrect behaviour of heredocs with expansions

From: <[email-masked]>
Date: Sat, 03 Dec 2022 08:25:38 +0100

Yuan Fu <[email-masked]> writes:

> What’s the return value of (treesit-node-at (point)) at that point?
> Probably the command_substitution node, and since it doesn’t have any
> children, treesit-node-first-child-for-pos would return nil.

(treesit-node-at (point) 'bash)
=> #<treesit-node (heredoc_body) in 12-56>

I forgot to say that point is before "text2", outside of the
command_substitution node.

> Yuan

tee << EOF
text1 $var
text2 $(echo cmd)
text3
$var2
EOF

Filling a test buffer with these contents and placing point before
"text2", we get

    (treesit-node-at (point) 'bash)
    => #<treesit-node (heredoc_body) in 12-56>

    (treesit-node-children (treesit-node-at (point) 'bash))
    => (#<treesit-node (simple_expansion) in 18-22>
        #<treesit-node (command_substitution) in 29-40>
        #<treesit-node (simple_expansion) in 47-52>)

This is now expected.

    (point)
    => 23

    (treesit-node-first-child-for-pos (treesit-node-at (point) 'bash) (point))
    => nil

This is not expected. One would expect this to return
command_substitution node, since it follows the position 23.