Bug 174597 - Code folding of compound statements
Summary: Code folding of compound statements
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-core (show other bugs)
Version: 4.0   Edit
Hardware: PC All
: P3 enhancement with 9 votes (vote)
Target Milestone: 5.0   Edit
Assignee: Anton Leherbauer CLA
QA Contact:
URL:
Whiteboard:
Keywords: contributed
: 213938 (view as bug list)
Depends on:
Blocks:
 
Reported: 2007-02-19 02:49 EST by Axel Mueller CLA
Modified: 2008-06-22 03:19 EDT (History)
5 users (show)

See Also:


Attachments
A non finished patch that solves the problem for reference only (12.48 KB, patch)
2008-01-19 16:19 EST, Elazar Leibovich CLA
no flags Details | Diff
Final version of the patch - please review and comment (19.65 KB, patch)
2008-01-20 01:21 EST, Elazar Leibovich CLA
no flags Details | Diff
A better version of the patch which enables case folding (20.94 KB, patch)
2008-01-20 16:09 EST, Elazar Leibovich CLA
no flags Details | Diff
Fixed patch, without JUnit tests yet (82.51 KB, patch)
2008-01-21 23:56 EST, Elazar Leibovich CLA
no flags Details | Diff
Final patch with JUnit tests, and Enum folding (88.94 KB, patch)
2008-01-23 16:00 EST, Elazar Leibovich CLA
bjorn.freeman-benson: iplog+
elazarl: review?
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Axel Mueller CLA 2007-02-19 02:49:49 EST
It would be very useful to have code folding for if statements and for loops.
Comment 1 Christo CLA 2007-02-27 01:30:23 EST
I would like to add switch and case statements to the list.
Comment 2 lebios CLA 2007-08-02 04:00:47 EDT
I'd like also to fold all the '{' '}' statement like for enum & struct..
Comment 3 chris CLA 2007-09-17 15:34:01 EDT
I'd love to see folding for "if" "else" "else if" "for" "while" "case" "switch" and simular constructs.
Comment 4 Nathan E CLA 2007-11-14 17:35:43 EST
I'd just like to add a "me too" to this enhancement request.
Comment 5 Anton Leherbauer CLA 2008-01-07 04:37:58 EST
*** Bug 213938 has been marked as a duplicate of this bug. ***
Comment 6 Elazar Leibovich CLA 2008-01-19 16:19:24 EST
Created attachment 87339 [details]
A non finished patch that solves the problem for reference only

Where should I send patches? Is there a mailing list?
Comment 7 Elazar Leibovich CLA 2008-01-20 01:21:18 EST
Created attachment 87346 [details]
Final version of the patch - please review and comment

The following patch should enable C statements folding. Please review it and apply it to the next version of CDT.
I'll be glad for comments about my patch quality.
If you need me to fix anything - do tell.
Thanks
Comment 8 Elazar Leibovich CLA 2008-01-20 16:09:01 EST
Created attachment 87362 [details]
A better version of the patch which enables case folding

This is a better version of the previous patch, it allows folding of case statements within switch.
It'll only fold case statements in the body of a switch statement, that is:
switch (a) {
case 1:
break;
}//possible
switch (a) {
if (0) {
  case 1:
  break;
}
}// not possible
Comment 9 Anton Leherbauer CLA 2008-01-21 06:39:01 EST
Thanks for the patch. It looks quite good!
I would like you to make the following changes:

- Please keep Java 1.4 source level
- Remove debug print statements (or prefix with "if (DEBUG)")
- default clause in switch is not handled correctly
- The new checkbox on the preference page is wrongly connected to the option for initial folding of inactive preprocessor branches
- JUnit tests would be great! See class FoldingTest in org.eclipse.cdt.ui.tests
- Add a contributor note to the Copyright comment of each file
Comment 10 Elazar Leibovich CLA 2008-01-21 23:56:15 EST
Created attachment 87468 [details]
Fixed patch, without JUnit tests yet

This fixes all the issues you asked me to fix.
Thanks alot.
I didn't add the unit tests yet, since I didn't think of a good way to get the projection information from a file, but I want to do that until weekend.
Please, apply the patch even before the JUnit tests.
Comment 11 Anton Leherbauer CLA 2008-01-22 04:27:41 EST
(In reply to comment #10)
> Created an attachment (id=87468) [details]
> Fixed patch, without JUnit tests yet
> This fixes all the issues you asked me to fix.

Thanks, I noticed a lot of formatting changes. Is it OK if I revert those changes before applying?

> I didn't add the unit tests yet, since I didn't think of a good way to get the
> projection information from a file, but I want to do that until weekend.

The class FoldingTest already has support to verify projection positions.
Comment 12 Elazar Leibovich CLA 2008-01-23 16:00:53 EST
Created attachment 87696 [details]
Final patch with JUnit tests, and Enum folding

This patch has Enum folding support and JUnit tests updated to test the patch as well.
Please have a look at it, you may change whatever you see which would be better.
Comment 13 Chris Grey CLA 2008-01-23 18:55:41 EST
If you've installed one of the other previous patches, you may need to redownload org.eclipse.cdt.ui and org.eclipse.cdt.ui.tests from CVS or it may not build correctly...at least that's the experience I had. 
Comment 14 Anton Leherbauer CLA 2008-01-24 04:53:31 EST
(In reply to comment #12)
> Created an attachment (id=87696) [details]
> Final patch with JUnit tests, and Enum folding
> This patch has Enum folding support and JUnit tests updated to test the patch
> as well.

Thanks. I noticed that this new patch creates duplicate positions due to the additional handling of declarations in the ast visitor. I reverted this to the version of the previous patch and re-added the handling for enums.

Applied to HEAD.
Comment 15 Chris Grey CLA 2008-01-24 07:56:14 EST
I'm not sure if I'm running into a different problem or a problem introduced by this latest patch. But here's the scenario, 
1. Start off with everything expanded

2. Collapse All

3. Expand something (anything)

4. Add or Modify some code and summon the Template Proposal to suggest something

5. After selecting something from the Template Proposal list, EVERYTHING wants to expand on its own. However it's doing a bad job of it because some things are only partially expanded...yes partially expanded and there are the dot-dot elipses all over the screen where the "unexpaded" parts are. 

I know I've seen the partial expansion of things before this patch was developed. I even saw that on v3.3 where only the functions would collapse. So I don't think the bug is directly related to this patch. Without knowing the code, I can't say this for sure, but perhaps the bug is in whatever supporting code this patch is making use of.

I've been using almost every one of the patches listed above, and I don't recall this happening with any of them except this latest one (2008-01-23).

Thoughts?
Comment 16 Elazar Leibovich CLA 2008-01-24 09:02:32 EST
1) Oops, indeed I tried to add folding to long arrays (int a[] = {1,2,3})) but forgot to revert that before creating the patch.
2) Did you check that you didn't break the JUnit tests? I'll try to check it and propose another patch with the JUnit tests enabled.
Comment 17 Anton Leherbauer CLA 2008-01-24 09:27:20 EST
(In reply to comment #15)
Please update to CVS HEAD.

(In reply to comment #16)
> 1) Oops, indeed I tried to add folding to long arrays (int a[] = {1,2,3})) but
> forgot to revert that before creating the patch.

I actually took the previous patch, as I mentioned in comment 14.

> 2) Did you check that you didn't break the JUnit tests? I'll try to check it
> and propose another patch with the JUnit tests enabled.

Don't bother, I already fixed the tests.
Comment 18 Chris Grey CLA 2008-01-24 10:08:08 EST
I updated org.eclipse.cdt.ui and org.eclipse.cdt.ui.tests from HEAD, and it did the same thing with the unfolding. I've deleted all cdt projects so I can redownload them all from HEAD. I'll see if that makes any difference. Doing this has helped in the past with other issues I had. 
Comment 19 Anton Leherbauer CLA 2008-01-24 10:44:40 EST
(In reply to comment #18)
Please open a new bug if the problem persists.