Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JavaScript if block without brackets indentation #30933

Closed
AshleyScirra opened this issue Jul 18, 2017 · 38 comments
Closed

JavaScript if block without brackets indentation #30933

AshleyScirra opened this issue Jul 18, 2017 · 38 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug editor-autoindent Editor auto indentation issues

Comments

@AshleyScirra
Copy link

AshleyScirra commented Jul 18, 2017

  • VSCode Version: Code 1.14.1 (2648980, 2017-07-13T19:18:47.188Z)
  • OS Version: Windows_NT ia32 10.0.15063
  • Extensions: none

Steps to Reproduce:

As of the 1.14 update, typing JS code has really annoying indentation behavior. I can't figure out why it changed and I can't find any relevant settings to try to change.

To reproduce, type this:

if (cnd) <enter> {

Expected result (pre-1.14):

if (cnd)
{

Observed result (1.14):

if (cnd)
    {

This is the worst indentation style!

@vscodebot vscodebot bot added editor editor-find Editor find operations labels Jul 18, 2017
@rebornix rebornix added editor-autoindent Editor auto indentation issues and removed editor-find Editor find operations labels Jul 18, 2017
@mjbvz mjbvz added the bug Issue identified by VS Code Team member as probable bug label Jul 19, 2017
@rebornix
Copy link
Member

@mjbvz do you think our indentNextLinePattern is a little bit unnecessary for TypeScript/JavaScript ? It seams that this pattern is bothering ppl instead of helping them out most of the time as writing brackets around blocks is more common.

@rebornix
Copy link
Member

rebornix commented Jul 19, 2017

Related issues #31027

@rebornix rebornix changed the title JavaScript code indents broken in 1.14 JavaScript if block without brackets indentation Jul 19, 2017
@mjbvz
Copy link
Collaborator

mjbvz commented Jul 19, 2017

I think enough libraries and developers do write single statement ifs that removing indentNextLinePattern entirely will be more annoying. Can we modify the regex to work around this?

@rebornix
Copy link
Member

@mjbvz I'm thinking about taking one step back on indentOnType. Usually the only time that indentOnType kicks in and helps you out is when the content matches decreaseIndentPattern. Maybe a workaround here is only adjust the indentation when it matches decreaseIndentPattern otherwise users decide what the indent level they want.

Right now I don't know how to make the regex aware of context in this case.

@mjbvz
Copy link
Collaborator

mjbvz commented Jul 19, 2017

Yes I think the expected behavior here would be to indent the next line only if there is no other content after the cursor. Would we be able to achieve that without indentNextLinePattern?

@simonl65
Copy link

Expected behaviour should be same as pre 1.14, please.

@izimuth
Copy link

izimuth commented Jul 20, 2017

I am having this exact same issue, but i can't find the indentNextLinePattern setting. Also its only happening if I have a project open, opening JavaScript files outside of a project it works fine.

@ericdrobinson
Copy link

Does anyone know what feature addition/change caused this to occur? I'm interested in understanding why this change came in as it impacts me every time I write control flow code (if, for, while, etc.). This has been a constant source of frustration with TS/JS files since the 1.14 release (am currently on 1.14.2).

@anickle060193
Copy link

A temporary work-around is to downgrade to version 1.13.

@simonl65
Copy link

OK, I'm back - I don't have any setting with indentNextLinePattern - I'm now on 1.14.2

@rebornix Why can't the feature that was added in 1.14 be removed - this is really annoying

@davidstlyoui
Copy link

@mjbvz you marked this as duplicate with #31272 and closed it, then you went and close #31272 and marked it as duplicate with this.
Most issues are pointing to this one as the real one.

@anickle060193
Copy link

@davidstlyoui This issue hasn't actually been closed. I think Github is just displaying the duplicate message incorrectly for this issue.

@mjbvz
Copy link
Collaborator

mjbvz commented Jul 31, 2017

indentNextLinePattern is an internal configuration name. There is no user setting to change it

@rebornix Have you had a chance to take another look into this issue?

@mjbvz mjbvz closed this as completed in e9764d9 Jul 31, 2017
@simonl65
Copy link

@mjbvz Why have you closed this? I thought this was where we were tracking this issue (which is why 31272 and 30691 were closed)

@ericdrobinson
Copy link

@simonl65 It looks like he closed it as part of this commit. It looks like typing "Fixes [Issue #]" into the commit message will also close that issue as part of the workflow. See this help page.

@mjbvz
Copy link
Collaborator

mjbvz commented Jul 31, 2017

@simonl65 I closed this issue with a change that should resolve the problem. Please try it out in the next VS Code insiders builds

@simonl65
Copy link

I just learned something! Thanks - I'll give that a try when vscode next updates.

@simonl65
Copy link

Hmm, so I couldn't wait - I downloaded the insiders build (1.15.0-insider)!

Sorry to say - it's worse! I now get the following:

if(x)
    {

...that's four spaces before the { (1.14 only gave 2 spaces)

If it helps, my non-default settings are:

{
    "editor.insertSpaces": false,
    "editor.tabSize": 2,
    "workbench.sideBar.location": "left",
    "editor.wordWrapColumn": 82,
    "editor.renderIndentGuides": true,
    "editor.rulers": [
        82,
        120
    ],
    "window.zoomLevel": 0,
    "workbench.iconTheme": "vscode-great-icons",
    "workbench.colorTheme": "Visual Studio Dark",
    "terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe"
}

This is a clean install of 1.15.0-insider - no extensions added.

What have I missed?

Question: Why can't the auto-indent stuff just revert to how things were in 1.13 - that worked fine?

@mjbvz
Copy link
Collaborator

mjbvz commented Jul 31, 2017

@simonl65 This change just went in and is not yet in any build. You need to wait for the next nightly insiders build to pick up this change

@simonl65
Copy link

@mjbvz Oops - over eager! Will try it tmz. Thanks for your efforts 👍

@simonl65
Copy link

simonl65 commented Aug 5, 2017

@mjbvz Sorry to say: it's not changed - still indenting the {.

BTW: Correct behavior in PHP - this affects JS & TS.

This is a real PITA

@mattbierner
Copy link
Contributor

@simonl65 Please record a gif of exactly what you are seeing. Here's what I see:

aug-05-2017 17-13-17

@simonl65
Copy link

simonl65 commented Aug 6, 2017

@mjbvz Not sure how to ad a gif, so here are the steps:

  1. Type if(1)
  2. Hit enter
  3. Cursor drops to next line but is indented (should be below the i of if
  4. Type {
  5. Type enter
  6. Result is:
if(1)
  {
    |
  }

Expected result:

if(1)
{
  |
}

@TheCyberRonin
Copy link

@mattbierner This is on the insiders build (1.16.0), I believe it's the same issue.
2017-08-11_08-27-11

@AshleyScirra
Copy link
Author

The original issue still reproduces in 1.15. It is not fixed!

@cdaringe
Copy link

cdaringe commented Aug 15, 2017

indent-loco mov

watch me shift these lines down. ^. it expected that these lines do not get indented on shift.

doh! is this the correct place for this report, @mjbvz, or shall i add my GIF elsewhere?

thx :)

@ericdrobinson
Copy link

@Rxswyers Yes. That is exactly the issue. It is truly frustrating.

@simonl65
Copy link

@cdaringe I'm not sure that's the same issue - I guess you're using ALT + downArrow?

I don't get that in a javascript file either - which language mode are you in?

@AshleyScirra
Copy link
Author

Can someone re-open this issue since it is not fixed? Otherwise I will probably file it again. It's really annoying.

@cdaringe
Copy link

@simonl65

ALT + downArrow?

yep!

I don't get that in a javascript file either

javascript language setting.

@mjbvz
Copy link
Collaborator

mjbvz commented Aug 16, 2017

The original reported issue was fixed. I've opened #32653 to track to track the other case discussed in the comments

@ericdrobinson
Copy link

ericdrobinson commented Aug 16, 2017

@mjbvz But that isn't the case at all. Here's what the original reported issue read as:

To reproduce, type this:

if (cnd) <enter> {

Expected result (pre-1.14):

if (cnd)
{

Observed result (1.14):

if (cnd)
   {

As explained in many subsequent comments, this is still an issue.

You happened to fix a related bug, just not the one described in this issue. Your fix gif shows that you type if (1) {} and then go back and hit enter between the if-condition and the braces. That is not the flow that the bug describes.

mjbvz added a commit that referenced this issue Aug 16, 2017
@AshleyScirra
Copy link
Author

AshleyScirra commented Aug 17, 2017

@mjbvz - the original issue I reported does still reproduce for me in 1.15 following the same steps. It's not fixed.

@TheCyberRonin
Copy link

It's fixed in the insider release. Be patient for it to get to the stable build. @AshleyScirra

@simonl65
Copy link

Yay - that fixed it! @mjbvz Thank you.

@azarus
Copy link

azarus commented Aug 28, 2017

@mjbvz its still not fixed, just grabbed the latest version on a different fresh installed cmputer and this is still here. This is ridiculous.

@simonl65
Copy link

@azarus I don't think the fix has made it to the release version yet. I'm guessing you're on version 1.15.x, but the fix is in 1.16.0-insider - which you can download from https://code.visualstudio.com/insiders

@azarus
Copy link

azarus commented Aug 28, 2017 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug editor-autoindent Editor auto indentation issues
Projects
None yet
Development

No branches or pull requests