Bug 236160 - C Block comment closes on next line when # is a first character on line
Summary: C Block comment closes on next line when # is a first character on line
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-core (show other bugs)
Version: 5.0   Edit
Hardware: All All
: P3 minor (vote)
Target Milestone: 5.0.1   Edit
Assignee: Anton Leherbauer CLA
QA Contact:
URL:
Whiteboard:
Keywords: contributed
Depends on:
Blocks:
 
Reported: 2008-06-06 22:22 EDT by Andrew Gvozdev CLA
Modified: 2009-01-09 15:07 EST (History)
0 users

See Also:


Attachments
Changes to improve adding/removing C style block comments /* */ (33.30 KB, patch)
2008-06-12 00:39 EDT, Andrew Gvozdev CLA
no flags Details | Diff
Additional patch to add test cases to test suite (769 bytes, patch)
2008-06-18 20:59 EDT, Andrew Gvozdev CLA
no flags Details | Diff
updated patch (38.81 KB, patch)
2008-07-01 23:36 EDT, Andrew Gvozdev CLA
aleherb+eclipse: iplog+
Details | Diff
mylyn/context/zip (422.45 KB, application/octet-stream)
2008-07-01 23:37 EDT, Andrew Gvozdev CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Gvozdev CLA 2008-06-06 22:22:18 EDT
Build ID: CDT 5.0.0-I200806020821

Steps To Reproduce:
1. Select second line in the example being careful not to select end of line (i.e. <home>, then <shift><end>)
#include <a.h>
#include <b.h>
#include <c.h>

2. Press <shift><ctrl>/

3. Block comment C-style is inserted ruining 3-rd line:
#include <a.h>
/*#include <b.h>
*/#include <c.h>

desired result:
#include <a.h>
/*#include <b.h>*/
#include <c.h>

Note that it works as expected if the line does not start with #, i.e.

int i;
/*int j;*/
int k;

---
Also, I would suggest an enhancement. Currently, if there is no selection, <ctrl><shift>/ has no effect. I suggest to comment out the whole line where the cursor is located.

More information:
Comment 1 Andrew Gvozdev CLA 2008-06-12 00:39:44 EDT
Created attachment 104613 [details]
Changes to improve adding/removing C style block comments /* */

I created a patch to handle block comments hopefully more consistent. I did not find any test cases, so I created a bunch both for adding and removing the comments. Please review.
Comment 2 Anton Leherbauer CLA 2008-06-12 03:30:55 EDT
Great! The JUnit test is much appreciated.
I'll schedule this for 5.0.1.
Comment 3 Andrew Gvozdev CLA 2008-06-18 20:59:01 EDT
Created attachment 105363 [details]
Additional patch to add test cases to test suite

I noticed that I missed adding the test cases to the test suite. Here is the patch for that.

By the way, Toni, thanks for very fast respond on the patch, very impressive and encouraging. Hopefully I can contribute some more to such fantastic project as CDT.
Comment 4 Anton Leherbauer CLA 2008-07-01 07:19:12 EDT
I found a few issues with this patch:
- Unfortunately, you cannot assume that the same line delimiter is used throughout the file.
- A NPE occurs when commenting the last line and the line does not end in a line delimiter.
- If the last line is a single line comment which does not end in a line delimiter, the block comment is wrong.

Please address these remaining issues. Thanks!
Comment 5 Andrew Gvozdev CLA 2008-07-01 23:36:49 EDT
Created attachment 106273 [details]
updated patch

The issues are fixed, please see updated patch. Check out additional test cases covering them.

In CDT, Ctrl-/ performs C++ style line commenting "//" even when a user is working with C code where such comments are illegal. Do you think it's worth considering mapping Ctrl-/ to block comments for such files? I think that users in mass are not even aware of Ctrl-Shift-/ combination for such a common need as commenting. Actually, we are working with mix of C and C++ code so this would be needed to be dependent on file extension I guess. And users from other organizations could work with different C dialect accepting C++ comments. A flag in preferences? Just thinking.
Comment 6 Andrew Gvozdev CLA 2008-07-01 23:37:02 EDT
Created attachment 106274 [details]
mylyn/context/zip
Comment 7 Andrew Gvozdev CLA 2008-07-01 23:46:38 EDT
Sigh. Can't figure for myself yet if mylyn is more help or more trouble. Is it possible to remove this automatically attached 400Kb context file.
Comment 8 Anton Leherbauer CLA 2008-07-07 05:24:02 EDT
(In reply to comment #5)
> The issues are fixed, please see updated patch. Check out additional test cases
> covering them.

Thanks for the update.
I have applied the patch with minor modifications:
- comments
- added support for doc-style comment partitions
Fixed in 5.0.1 and HEAD > 20080707.

> In CDT, Ctrl-/ performs C++ style line commenting "//" even when a user...

I suggest to create a separate enhancement request for that.