bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#59633: 29.0.50; tree-sitter-bash: Incorrect behaviour of heredocs wi


From: Yuan Fu
Subject: bug#59633: 29.0.50; tree-sitter-bash: Incorrect behaviour of heredocs with expansions
Date: Fri, 2 Dec 2022 16:50:20 -0800


> On Dec 2, 2022, at 8:26 AM, miha@kamnitnik.top wrote:
> 
> Yuan Fu <casouri@gmail.com> writes:
> 
>> miha@kamnitnik.top writes:
>> 
>>> 1. Visit empty buffer test in fundamental mode (C-x b test RET)
>>> 2. Insert
>>> 
>>> tee << EOF
>>> text1 $var
>>> text2 $(echo cmd)
>>> text3
>>> $var2
>>> EOF
>>> 
>>> 3. Put point before "text2"
>>> 4. M-x load-library RET treesit RET
>>> 5. M-: (treesit-node-children (treesit-node-at (point) 'bash))
>>> 
>>>    => (#<treesit-node (simple_expansion) in 18-22>
>>>        #<treesit-node (command_substitution) in 29-40>)
>>> 
>>>   Note that this list is incorrect, "$var2" at the end of heredoc is
>>>   missing.
>>> 
>>> 6. M-: (treesit-node-first-child-for-pos (treesit-node-at (point) 'bash) 
>>> (point))
>>> 
>>>   => nil
>>> 
>>>   Expected return value here is #<treesit-node (command_substitution) in 
>>> 29-40>
>>> 
>>> I'm not sure if this bug is on Emacs, tree-sitter-bash or even
>>> tree-sitter itself and I don't know how to check.
>>> 
>>> tree-sitter-bash version: 0.19.0.r19.g77cf8a7-1
>>> tree-sitter version: 0.20.7-1
>>> 
>>> Thanks and best regards.
>> 
>> Thanks. This is the tree produced by tree-sitter, does it match your
>> expectation?
>> 
>> (heredoc_body
>> (simple_expansion $ (variable_name))
>> (command_substitution $(
>>  (command
>>   name: (command_name (word))
>>   argument: (word))
>>  ))
>> (simple_expansion $ (variable_name)))
>> 
>> treesit-node-at gives you the _smallest_ node at point, maybe that’s why
>> you didn’t see expected behavior?
>> 
>> Yuan
> 
> The latest commit to tree-sitter-bash is
> 
> commit 4488aa41406547e478636a4fcfd24f5bbc3f2f74
> Author: João P. L. Carvalho <jaopaulolc@gmail.com>
> Date:   Sun Nov 27 20:39:41 2022 -0700
> 
>    Fix scanning of heredoc_body to allow empty bodies (#137).
> 
> Seems like it has fixed the problem described in the 5. step and the
> tree produced by tree-sitter is now expected.
> 
> The problem in the 6. step is still present though. With point in front
> of command_substitution, on would expect
> 
>    (treesit-node-first-child-for-pos (treesit-node-at (point) 'bash) (point))
> 
> to return the command_substitution node instead of returning nil.

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.

Yuan




reply via email to

[Prev in Thread] Current Thread [Next in Thread]