GNU bug report logs -
#59686
30.0.50; tree-sitter indentation in some loops and conditional statements is wrong
Previous Next
Full log
Message #11 received at 59686 <at> debbugs.gnu.org (full text, mbox):
On 2 December 2022 06:13:42 CET, Yuan Fu <casouri <at> gmail.com> wrote:
>
>Bruce Stephens <bruce.stephens <at> isode.com> writes:
>
>> With the following file I would expect foo(i) to be indented to just two
>> indents (like the first one), but they are not. Similarly for many other
>> compound statements where the opening spans more than one line.
>>
>> // -*- c-ts -*-
>> int main() {
>> for (int i=0; i<10; ++i) {
>> foo(i);
>> }
>>
>> for (int i=0;
>> i<10;
>> ++i) {
>> foo(i);
>> }
>> }
>
>I see, that’s because the indent rule finds the BOL of the line where
>the "{" is on, and indents from there. Theo, WDYT? Does indent style
>fix this, or we should change the indent rules?
>
>Yuan
I've seen this issue myself, and have tried several combinations to fix it. It is trivial to fix this particular case, but because compound_statement is used everywhere problems will pop up other places. The fix here would be some grand-parent-bol function, but if my memory serves that would mess up the else in an if else. I'm happy to see this fixed, but just remember that it's not _super_ trivial.
Other languages exhibit similar issues, but with other constructs.
Lastly, I _did_ fix most of these, but that required using query as the matcher in simple-indent-rules, which made indenting slower, and I needed one rule for almost every construct in a language.
I'm sure she fix can be simple, but I'm a little blind to it right now. My eyes are bleeding tree-sitter nodes at the moment, so I might not see clearly :P
This bug report was last modified 2 years and 207 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.