Bug 311617 - [formatter] provide default tags to enable/disable formatter
Summary: [formatter] provide default tags to enable/disable formatter
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.6   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: 3.6 RC1   Edit
Assignee: Frederic Fusier CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 311582
Blocks:
  Show dependency tree
 
Reported: 2010-05-04 15:51 EDT by Markus Keller CLA
Modified: 2010-05-17 04:27 EDT (History)
6 users (show)

See Also:
srikanth_sankaran: review+


Attachments
Proposed patch (5.40 KB, patch)
2010-05-06 05:51 EDT, Frederic Fusier CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Keller CLA 2010-05-04 15:51:35 EDT
Follow-up to bug 27079 comment 40

When bug 311582 is fixed, we can supply default tags to enable/disable the formatter.

Proposals so far:
- @formatter:off / @formatter:on
- //J-  /  //J+
Comment 1 Dop Sun CLA 2010-05-04 18:56:21 EDT
I much like // @formatter:on and // @formatter:off. 

But the small issue i can see is: if developers code it manually, there will be different forms (mostly because of spaces):

1. // @formatter: on
2. // @formatter:on
3. //@formatter:on
4. //@formatter: on

And I read from the context of bug 27079 comment 40, shows this may be problem, because it only detects the exact form matching. So spaces after // may not be problem, but space between on and : may be trouble.

So, if these two or similar are picked up, the related feature (request) will be:
1. Highlighting lines with these flags in the indicator bar (similar as TODO: but put on the right side only)
2. Have Context Assist to help input. But this will be a little bit tricky, since user may define any flags, and not necessarily has a common prefix for both: like <prefix>on/off or <prefix>+/-.

If 1st can be done, I vote +1 for // @formatter: on/ off
Comment 2 Dop Sun CLA 2010-05-04 18:57:46 EDT
sorry, should be bug 27079 comment 30, not 40.
Comment 3 Amenel Voglozin CLA 2010-05-05 06:16:18 EDT
I just don't see why spaces in the activating or deactivating tag should be a problem. If the tag is known as "@formatter:off" and someone writes "@formatter: off", adding a space where there should be no space, then the tag is not there.

I see no problem there. Especially when (as I said in this comment https://bugs.eclipse.org/bugs/show_bug.cgi?id=27079#c25) the user chooses how the tag is spelled. Unless that choice is no longer available, having to care for user inconsistency looks like too much niceness.

I'm on board for "@formatter:on/@formatter:off", which is very close to what was initially proposed (https://bugs.eclipse.org/bugs/show_bug.cgi?id=27079#c0). That would be a sort of credit/acknowledgement to Piotr.
Comment 4 Markus Keller CLA 2010-05-05 07:10:29 EDT
@formatter:off / @formatter:on
also looks fine to me. The spacing is not a problem, since // will not be part of the tags (and to support //, bug 311578 would first have to be fixed).

For content assist, it's too late for 3.6, but we could consider this for 3.7.
Comment 5 Frederic Fusier CLA 2010-05-05 07:44:55 EDT
+1 for @formatter:off / @formatter:on

The only minor issue I can see with these tags is that the Javadoc view currently highlights the word after the '@' character, even if it's not a block nor an inline javadoc tag (I guess it's a known issue), hence using this tag in a Javadoc will emphasize the 'formatter' but not the trailing ':on'/':off'...
Comment 6 Markus Keller CLA 2010-05-05 08:41:34 EDT
> Javadoc view currently highlights the word after the '@' character

See bug 39699 and its dependencies. But this is not a problem in practice, since it doesn't make sense to put these tags in Javadoc comments anyway (why would you want to have source code formatter controls in generated documentation?).
Comment 7 Dop Sun CLA 2010-05-05 08:45:39 EDT
(In reply to comment #4)
> @formatter:off / @formatter:on
> also looks fine to me. The spacing is not a problem, since // will not be part
> of the tags (and to support //, bug 311578 would first have to be fixed).
> 
> For content assist, it's too late for 3.6, but we could consider this for 3.7.

When I say space is a "small" problem, consider:
@formatter:off
@formatter: off

If my understanding of bug 27079 comment 30 correctly, it means that the second one will not be recognized.

And as of now, there are no indicator in the left or right indicator bar (like what TODO comment tag has been done), and no highlight with for/back color in the code, so, if there is a space in between, and it may be mistakenly ignored. Of cause, it can be easily discovered and fixed once the developer tries to format the code.

I'm happy to agree with all votes so far, +@formatter:off and @formatter:on (which does not have space, for this I feel a little bit strange is, usually, a space is expected after colon).
Comment 8 Dani Megert CLA 2010-05-05 11:32:03 EDT
Marking RC1 since this will go in along with bug 311582.

+1 for RC1.
Comment 9 Olivier Thomann CLA 2010-05-05 12:07:52 EDT
(In reply to comment #7)
> And as of now, there are no indicator in the left or right indicator bar (like
> what TODO comment tag has been done), and no highlight with for/back color in
> the code, so, if there is a space in between, and it may be mistakenly ignored.
> Of cause, it can be easily discovered and fixed once the developer tries to
> format the code.
If the tag doesn't exactly match the given tags, then it won't disable the formatter. The user has to specify exact tags.

> I'm happy to agree with all votes so far, +@formatter:off and @formatter:on
> (which does not have space, for this I feel a little bit strange is, usually, a
> space is expected after colon).
Doesn't bother me not to have a space after a colon.

We provide a default. Nothing prevents users from choosing a different one.
Code assist will be added for 3.7.
Comment 10 Olivier Thomann CLA 2010-05-05 13:49:39 EDT
Frédéric,

Please add @formatter:off / @formatter:on as disabling and enabling default tags.
Thanks.
Comment 11 Frederic Fusier CLA 2010-05-06 05:51:01 EDT
Created attachment 167278 [details]
Proposed patch
Comment 12 Frederic Fusier CLA 2010-05-06 06:16:00 EDT
Srikanth, can you please review?
Thanks
Comment 13 Srikanth Sankaran CLA 2010-05-06 07:06:51 EDT
Patch looks good.
Comment 14 Frederic Fusier CLA 2010-05-06 07:40:53 EDT
(In reply to comment #11)
> Created an attachment (id=167278) [details]
> Proposed patch

Released for 3.6RC1 in HEAD stream.
Comment 15 Srikanth Sankaran CLA 2010-05-17 01:42:42 EDT
Verified for 3.6RC1 using Build id: I20100513-1500
Comment 16 Dop Sun CLA 2010-05-17 02:49:22 EDT
A quick one: spell check takes @format:off and @format:on as warning, and currently, all 3 options available are not good enough to handle it.

(don't know which component to take care the spell check, so not reporting it)
Comment 17 Dani Megert CLA 2010-05-17 04:27:15 EDT
(In reply to comment #16)
> A quick one: spell check takes @format:off and @format:on as warning, and
> currently, all 3 options available are not good enough to handle it.
> 
> (don't know which component to take care the spell check, so not reporting it)
Good point - I've fixed this in HEAD.