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

Bug 356606

Summary: [formatter] Unwanted alignment on Enter when inside array literal
Product: [WebTools] JSDT Reporter: Mark Macdonald <mamacdon>
Component: GeneralAssignee: Patrik Suzzi <psuzzi>
Status: RESOLVED FIXED QA Contact: Chris Jaun <cmjaun>
Severity: normal    
Priority: P3 CC: bugs, cbridgha, cmjaun, dajester2005, gautier.desaintmartinlacaze, gorkem.ercan, ibuziuk, jon.rimmer, nek.narqo, nsand.dev, omax, psuzzi, rulatir, tborychowski, thatnitind
Version: 3.3Flags: cbridgha: pmc_approved+
cmjaun: review? (cmjaun)
Target Milestone: 3.8.1   
Hardware: PC   
OS: Windows 7   
See Also: https://git.eclipse.org/r/79027
https://git.eclipse.org/r/79660
https://git.eclipse.org/c/jsdt/webtools.jsdt.git/commit/?id=d1cf6821fb18fd72631c99d1880a676bf722ab3d
Whiteboard: RHT PMC_Approved

Description Mark Macdonald CLA 2011-09-02 10:36:52 EDT
Eclipse 3.7 (I20110613-1736)
JSDT 1.3.0 (20110527214303)
WTP 3.3.0 (20100921193530)


1. Create a new JavaScript file and add this code:
function() {
	var myArray = [];
}
2. Put the editing caret between the square brackets, and press Enter.
3. You get
function() {
	var myArray = [
	               ];
}

Inside array literals, pressing Enter causes the editor to insert spaces to align the new line with the opening [ bracket. I expected it to just increase the indentation level.

This happens when using a new workspace with all the default preference settings.
Comment 1 Piotr Dobrogost CLA 2012-07-16 15:47:27 EDT
Issue raised also at http://stackoverflow.com/questions/7141183/
Comment 2 Tomasz Borychowski CLA 2012-08-25 14:47:51 EDT
Please vote for this bug!
Comment 3 Vladimir Varankin CLA 2013-01-03 07:54:49 EST
Guess this could be fixed wis kind of patch: https://github.com/narqo/webtools.jsdt.core/commit/1d40c05f5fc66b39607ddf9bbaf7d6349e52008b

NOTE: Actually I got no Java and Eclipse PDE experience, but I'm on my way learning :)
Comment 4 Chris Jaun CLA 2013-10-29 17:26:31 EDT
Vladimir, before we can accept any patch from you, you need to sign the Contributor License Agreement.

http://wiki.eclipse.org/Development_Resources/Contributing_via_Git#Eclipse_Foundation_Contributor_License_Agreement

Thanks,
Chris
Comment 5 Jesse Shaffer CLA 2014-08-06 17:48:58 EDT
This single issue forces me to install the behemoth that is Aptana. I must agree with a more recent reporting of the same issue (Bug 419931) that it is a "hideous, broken nightmare", and it "feels actively user-hostile".

And forgive me, but it seems a bit ridiculous that this bug is still "new" (nevermind still open) after nearly 3 years, and a year-and-a-half-old potential fix.
Comment 6 Szczepan Holyszewski CLA 2015-11-03 21:50:09 EST
(In reply to Chris Jaun from comment #4)
> Vladimir, before we can accept any patch from you, you need to sign the
> Contributor License Agreement.
> 
> http://wiki.eclipse.org/Development_Resources/
> Contributing_via_Git#Eclipse_Foundation_Contributor_License_Agreement
> 
> Thanks,
> Chris

Patch exists for two years. Stupid, arbitrary, harmful bureaucratic procedures prevent it from being applied.
Comment 7 Nitin Dahyabhai CLA 2016-07-19 14:40:30 EDT
(In reply to Szczepan Holyszewski from comment #6)
> Patch exists for two years. Stupid, arbitrary, harmful bureaucratic
> procedures prevent it from being applied.

Requiring a signed CLA protects us all and ensures Eclipse will remain legally available for you to download and use in the future.

https://www.eclipse.org/legal/clafaq.php
Comment 8 Eclipse Genie CLA 2016-08-15 00:57:58 EDT
New Gerrit change created: https://git.eclipse.org/r/79027
Comment 9 Ilya Buziuk CLA 2016-08-17 07:30:20 EDT
Is it possible to imlement the following formatting behaviour:

1. var myArr = [|] 

2. var myArr = [
        |
   ]

I think this is a better option for array formatting
Comment 10 Gorkem Ercan CLA 2016-08-23 13:41:04 EDT
*** Bug 419931 has been marked as a duplicate of this bug. ***
Comment 11 Eclipse Genie CLA 2016-08-24 15:35:33 EDT
New Gerrit change created: https://git.eclipse.org/r/79660
Comment 12 Patrik Suzzi CLA 2016-08-24 15:39:06 EDT
With the provided change is implemented the expected behavior, except we're using spaces instead of tabs. 
See: http://i.imgur.com/nS02cOS.gif
Thanks to all for the help in fixing this, especially to Shane, Angel, Nitin and Amisevsk.
Comment 13 Jesse Shaffer CLA 2016-08-24 15:55:17 EDT
(In reply to Patrik Suzzi from comment #12)
> With the provided change is implemented the expected behavior, except we're
> using spaces instead of tabs. 
> See: http://i.imgur.com/nS02cOS.gif
> Thanks to all for the help in fixing this, especially to Shane, Angel, Nitin
> and Amisevsk.

I did try replying with an email, but it does not seem to have applied it to this issue, so appologies if I repeat myself.

First of all, thank you for taking time to address this.  This one problem had been a perpetual thorn in my side, and I'm anxious to see it resolved.

However, from your example, that doesn't seem to be the expected behavior at all.  If I have my formatter set up to use tab indents, I should hit enter once and have the line indented by one tab.  Just like any other brackets (like braces for a function body for instance).  Your gif shows me that you have to hit enter and have to clear out a bunch of spaces to get to the desired indentation level before adding additional lines, which is the problem I currently have.  That is not an acceptable solution.

Ideally it should work like Atom or Sublime when it comes to indenting array initializers.
Comment 14 Jesse Shaffer CLA 2016-08-24 16:00:45 EDT
(In reply to Jesse Shaffer from comment #13)

To expound upon my last comment,

If your indent is set to 4-space indent, This is my expected result:

// | represents cursor position
// ^ represents a single space character

// before hitting enter
myArray=[|]; 

// after hitting enter
myArray=[
^^^^|
]



Again for tab indentation:

// | represents cursor position
// ---> represents a single tab character

// before hitting enter
myArray=[|]

// after
myArray=[
--->|
]

Again, from the gif example, it appears that the cursor is indented with spaces all the way to the closing bracket, and then to "fix" the indentation you backspace to get it where you want it, which is not acceptable IMO.
Comment 15 Patrik Suzzi CLA 2016-08-24 16:05:22 EDT
The bugfix in changeset 2 uses tabs. 
See http://i.imgur.com/CD0HiAa.gif
Comment 16 Jesse Shaffer CLA 2016-08-24 16:09:28 EDT
Patric(In reply to Patrik Suzzi from comment #15)
> The bugfix in changeset 2 uses tabs. 
> See http://i.imgur.com/CD0HiAa.gif

I stand pleasantly corrected, thank you!
Comment 17 Patrik Suzzi CLA 2016-08-24 16:12:38 EDT
Note for PMC review

This is the changeset: https://git.eclipse.org/r/#/c/79660/2

This bugfix makes more immediate the creation of arrays in JavaScript. 

This issue is around since a couple of years, and several developers already pointed this as a major flaw (i.e. Jesse, in this same bug ). 

AFAIK, there is no workaround. 
This fix just improves the user experience. 

The possible impact is little, as it affects only sections of code starting with '[', hence only arrays.
Comment 18 Patrik Suzzi CLA 2016-08-24 16:32:17 EDT
(rewriting the same things as above with a better model)
PMC Defect Candidate info: 

0. This is the changeset: https://git.eclipse.org/r/#/c/79660/2

1. This bugfix makes more immediate the creation of arrays in JavaScript. AFAIK, there is no workaround. 

2. This issue is around since a couple of years, and several developers already pointed this as a major flaw (i.e. Jesse, in this same bug ). 

3. Tested manually on a launch configuration. 

4. The possible impacts are little, as it affects only sections of code starting with '[', hence only arrays.
Comment 19 Gautier de SAINT MARTIN LACAZE CLA 2016-08-25 04:59:50 EDT
Thanks Patrik.
Comment 21 Piotr Dobrogost CLA 2016-08-25 08:33:47 EDT
Reported: 2011-09-02 10:36 EDT by Mark Macdonald
Modified: 2016-08-25 08:23 EDT

5 years to fix basic formatting bug... not bad.
No wonder people left Eclipse for JetBrains' IDEs.

Regards,
Happy user of PyCharm for the last 4 years.

ps.
Sorry, but I couldn't resist.
Comment 22 Ilya Buziuk CLA 2016-08-25 09:12:17 EDT
@Piotr this is a fair point indeed. However, there is another side of the coin - 
The project was in a deep support phase for many years and our new team take over it starting from the begginning of 2016. The point is that we can not fix all in JSDT in one go, but we are ready to fix it step-by-step. Basically, this bug was fixed only because "dajester2007" speak up about it in the comment to the JSDT 2.0 Webinar video - https://www.youtube.com/watch?v=UxGwu2adzIc . So, please if there is smth. irritable - let us know - bugzilla, mailing list, stack overflow, utube etc. We do know that there are dozens of problem in JSDT, but we are ready to hear about them and ready to fix them