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

From: Yuan Fu <[email-masked]>
Date: Tue, 13 Dec 2022 20:01:31 -0800

Yuan Fu <[email-masked]> writes:

> <[email-masked]> writes:
>
>> 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.
>
> Ah, I (finally) see what you mean. I agree that it should return the
> command_substitution node. It seems that tree-sitter returns nil
> whenever POS is not in a child node. I need to see what’s the problem
> here since treesit-node-first-child-for-pos is just a think wrapper
> around the C counterpart.

Seems to be tree-sitter-bash problem, I submitted an issue at
https://github.com/tree-sitter/tree-sitter-bash/issues/139

Yuan