Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 271937

Summary: Several code folding issues
Product: [Tools] CDT Reporter: plastiquefantastique
Component: cdt-editorAssignee: Project Inbox <cdt-editor-inbox>
Status: RESOLVED FIXED QA Contact: Anton Leherbauer <aleherb+eclipse>
Severity: normal    
Priority: P3 CC: chumak.daniel.dev, johnhenrysmith, remy.suen, yevshif
Version: 5.0.2   
Target Milestone: 7.0   
Hardware: All   
OS: All   
Whiteboard:
Bug Depends on: 178203    
Bug Blocks:    
Attachments:
Description Flags
Unexpected marks on layout none

Description plastiquefantastique CLA 2009-04-11 10:51:08 EDT
Build ID: M20090211-1700

Steps To Reproduce:
1. Open code source (folding enabled)
2. Edit (copy/paste/cut etc.)
3. Sometimes folding fails to work (look at description)


More information:
There are several of those folding issues since a long while (using Eclipse CDT under XP, Xubuntu and OSX here), and I just today decided to add my report here. I've been reading a couple of familiar issues (like cutting code results in unfolding of other parts etc.), but I think there is a more generic issue, and probably at platform level.

Sometimes, after editing code (copy, paste, cut, etc.) the folding fails to recognize regions that are foldable and produces horrible code layout with partly folded and unfolded parts at boundaries that are actually _inside_ foldable areas. Sometimes foldable areas are not recognized at all anymore.

These bugs have been there since at least Eclipse 3.3 (I'm at 3.4.2 now, with the more advanced folding options), and it seems to get worse every new Eclipse major version step. Closing/reopening the source file helps to restore valid folding, but it is cumbersome, to say the least, if you work with big source files and naturally there's a lot of editing done.

Don't get me wrong. I love Eclipse. Even better with folding. But sometimes incorrect folding (or the complete mess-up it can produce in some cases like described above) can also make working with it way less pleasurable as it could be.

I would appreciate if people who are also getting annoyed of folding issues could add comments/votes/solutions or links to related discussion to this report.

Thanks!
Comment 1 Anton Leherbauer CLA 2009-04-15 07:08:00 EDT
Without reproducible example, I cannot do much about the issues.
Comment 2 plastiquefantastique CLA 2009-04-16 11:43:02 EDT
I'm going to try to add one or more examples in the next few days.
Comment 3 plastiquefantastique CLA 2009-05-06 11:56:48 EDT
I didn't have much time the last days, and mostly the files where this does happen consist of many hundred or thousand lines, so it's pretty difficult to find a pattern there, but I just managed to create a quick example to showcase how deleting some part inside a function can unfold other parts of the code which was initially folded. I hope to be able to single out other cases sometimes soon.

Folding Settings in Eclipse: everything checked apart from the last three options (comments, inactive preprocessor branches)

Code example (to be put into an empty new header file (*.h), the comment marks the part which should be deleted to observe the folding behaviour):

template <typename Type, typename Value>
struct Struct
{
    inline Type function1()
    {
        // comment
        switch (Value()())  // delete this switch block here
        {
            case 0:
                break;
            default:
                break;
        }
        return Type();
    }
    inline Type function2()
    {
        // comment
        return Type();
    }
    inline Type function3()
    {
        // comment
        return Type();
    }
    inline Type function4()
    {
        // comment
        return Type();
    }
};
Comment 4 Anton Leherbauer CLA 2009-05-07 08:09:42 EDT
Thanks for the test case. Some observations: The amount of deleted text influences how much of the following text is expanded. It looks like all folded text moving into the deleted area gets expanded. JDT shows the exact same behaviour, so I believe this is a general Platform/Text issue. 
I'll need to debug it in detail.
Comment 5 plastiquefantastique CLA 2009-05-07 13:11:32 EDT
Re: following text

There are situations where code before _and/or_ afterwards is unfolded, so while I think we are close to the issue, it seems that recalculating the folding is going wrong on a more generic level (it looks like the whole code gets recalculated on editing). Although it's certainly possible that both share the same source of the problem.
Comment 6 Anton Leherbauer CLA 2009-05-08 04:14:29 EDT
Associated with Platform bug 178203.
Comment 7 plastiquefantastique CLA 2009-05-25 10:32:13 EDT
It looks like the platform bug isn't going to fixed anytime soon, so that's why I'm out of here too (moving to Netbeans finally). Thanks and good luck everyone.
Comment 8 John Smith CLA 2010-01-22 05:05:15 EST
+ 1 to plastiquefantastique@gmx.de

Good luck guys, but Netbeans editor at least works without folding bugs, not talking about the other.
Comment 9 John Smith CLA 2010-05-07 08:50:32 EDT
Eclipse build id: 20100218-1602
Eclipse IDE for C/C++ Developers 1.2.2.20100209-1511

Probably this problem also belong to the bug:

1) Open few *.c files, their source code gets collapsed
2) Edit function body in file foo.c
3) Switch to file bar.c
4) Some parts of code in the file bar.c now have "horrible code layout with
partly folded and unfolded parts"
Comment 10 John Smith CLA 2010-05-07 08:51:48 EDT
(In reply to comment #9)
> Eclipse build id: 20100218-1602
> Eclipse IDE for C/C++ Developers 1.2.2.20100209-1511
> 
> Probably this problem also belong to the bug:
> 
> 1) Open few *.c files, their source code gets collapsed
> 2) Edit function body in file foo.c
> 3) Switch to file bar.c
> 4) Some parts of code in the file bar.c now have "horrible code layout with
> partly folded and unfolded parts"

5) If I switch back to foo.c, I notice that now some parts of it also have "horrible code layout with partly folded and unfolded parts"
Comment 11 Anton Leherbauer CLA 2010-06-11 04:51:38 EDT
(In reply to comment #10)
> (In reply to comment #9)
> > Eclipse build id: 20100218-1602
> > Eclipse IDE for C/C++ Developers 1.2.2.20100209-1511
> > 
> > Probably this problem also belong to the bug:
> > 
> > 1) Open few *.c files, their source code gets collapsed
> > 2) Edit function body in file foo.c
> > 3) Switch to file bar.c
> > 4) Some parts of code in the file bar.c now have "horrible code layout with
> > partly folded and unfolded parts"
> 
> 5) If I switch back to foo.c, I notice that now some parts of it also have
> "horrible code layout with partly folded and unfolded parts"

Screenshots would be helpful.
Did you try with more recent builds?
Comment 12 John Smith CLA 2010-06-20 04:47:45 EDT
(In reply to comment #11)
> (In reply to comment #10)
> > (In reply to comment #9)
> > > Eclipse build id: 20100218-1602
> > > Eclipse IDE for C/C++ Developers 1.2.2.20100209-1511
> > > 
> > > Probably this problem also belong to the bug:
> > > 
> > > 1) Open few *.c files, their source code gets collapsed
> > > 2) Edit function body in file foo.c
> > > 3) Switch to file bar.c
> > > 4) Some parts of code in the file bar.c now have "horrible code layout with
> > > partly folded and unfolded parts"
> > 
> > 5) If I switch back to foo.c, I notice that now some parts of it also have
> > "horrible code layout with partly folded and unfolded parts"
> 
> Screenshots would be helpful.
> Did you try with more recent builds?

Hi Anton, as the recent experience shows, the behavior I described occurs only if I enable\disable folding in between 1) - 5). And if don't and only fold\unfold than folding works as expected.

Should I look for examples\screenshots for the "enable\disable folding" issue, or such behavior of enable\disable folding is expected?
Comment 13 Anton Leherbauer CLA 2010-06-21 03:50:03 EDT
(In reply to comment #12)
> Hi Anton, as the recent experience shows, the behavior I described occurs only
> if I enable\disable folding in between 1) - 5). And if don't and only
> fold\unfold than folding works as expected.
> 
> Should I look for examples\screenshots for the "enable\disable folding" issue,
> or such behavior of enable\disable folding is expected?

Thanks for the clarification.
When you disable/enable folding, the folding state of the editor is reset.  There is no persistence of folding state, so this behavior is expected.
I am marking this bug fixed since the underlying platform bug 178203 has been addressed in 3.6 which was the main reason for the complaints in comment 0.  Please feel free to file new bugs as you encounter them.
Comment 14 John Smith CLA 2010-07-09 04:03:01 EDT
Created attachment 173838 [details]
Unexpected marks on layout

I've recently got such layout as attached. Everything is ok except for the unexpected(for me) "[...]" marks.

Is it expected to happen?
Comment 15 Anton Leherbauer CLA 2010-07-09 04:21:11 EDT
(In reply to comment #14)
> Created an attachment (id=173838) [details]
> Unexpected marks on layout
> 
> I've recently got such layout as attached. Everything is ok except for the
> unexpected(for me) "[...]" marks.
> 
> Is it expected to happen?

I see this occasionally also in the Java editor.  Might be a platform bug, but without reproducible scenario, it is hard to address.
Comment 16 John Smith CLA 2010-07-13 04:43:39 EDT
(In reply to comment #15)
> (In reply to comment #14)
> > Created an attachment (id=173838) [details] [details]
> > Unexpected marks on layout
> > 
> > I've recently got such layout as attached. Everything is ok except for the
> > unexpected(for me) "[...]" marks.
> > 
> > Is it expected to happen?
> 
> I see this occasionally also in the Java editor.  Might be a platform bug, but
> without reproducible scenario, it is hard to address.

Ok, will let you (or more relative bug?) know if I am able to find a scenario in the future.