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

Wrong auto-indentation in typescript #209802

Closed
Tracked by #216945
rzvc opened this issue Apr 8, 2024 · 22 comments · Fixed by #216500
Closed
Tracked by #216945

Wrong auto-indentation in typescript #209802

rzvc opened this issue Apr 8, 2024 · 22 comments · Fixed by #216500
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug editor-autoindent Editor auto indentation issues insiders-released Patch has been released in VS Code Insiders javascript JavaScript support issues typescript Typescript support issues verified Verification succeeded
Milestone

Comments

@rzvc
Copy link
Contributor

rzvc commented Apr 8, 2024

Does this issue occur when all extensions are disabled?: Yes

  • VS Code Version: 1.88.0
  • OS Version: Ubuntu 22.04

Steps to Reproduce:

if (true)<enter>
	{<enter>
	}

This seems to happen on for and while as well. In other languages auto-indentation doesn't happen after the first <enter> in the example. While it could be good as a feature, it would be great if on typing the opening bracket, it would automatically un-indent. Also, it seems like the kind of thing that needs a toggle, because it can backfire in multiple ways.

Another thing that I noticed was that the auto-indentation happens even if the if line is commented out.

// if (true)<enter>
	|<cursor ends up here>

This was not a problem in the previous version.

@StevenJohnston
Copy link

I too have this issue

@AndrewStovell
Copy link

+1 to also having this issue. Can confirm, If, Else If, For, While, and Arrow Functions affected. Functions & Switches are fine.
Have tried commenting out settings.json, and issue persists.

Version: 1.88.1 (user setup)
Commit: e170252
Date: 2024-04-10T17:41:02.734Z
Electron: 28.2.8
ElectronBuildId: 27744544
Chromium: 120.0.6099.291
Node.js: 18.18.2
V8: 12.0.267.19-electron.0
OS: Windows_NT x64 10.0.22631

@TheWyo
Copy link

TheWyo commented Apr 22, 2024

Seems to be a re-occurrence of #30933 from quite some time ago.

@1564047446
Copy link

yeah, the latest version must auto error. emmmm, how long fix the bug

@Jemt
Copy link

Jemt commented May 5, 2024

I wonder why this bug report does not have a billion upvotes. I have the same problem, and it makes it a pain to write code. I constantly have to fix it manually. I tried disabling all my extensions and clear both User settings (JSON) and Workspace settings (JSON), but to no eval.

This is what I experience in JS files:

image

Pressing ENTER after control flows such as if or for indents the cursor like shown above, where it previously placed the cursor right below the if part.

In the example below I pressed ENTER after the function() declaration on line 5 which caused incorrect indentation in the opposite direction:

image

Previously it placed the cursor right below the [] part.

Things seems to work fine for PHP files.

Tested with VSCode 1.89.0 (commit b58957e) on macOS 12.7.2.

"About Visual Studio Code":
Version: 1.89.0
Commit: b58957e
Date: 2024-05-01T02:10:10.196Z
Electron: 28.2.8
ElectronBuildId: 27744544
Chromium: 120.0.6099.291
Node.js: 18.18.2
V8: 12.0.267.19-electron.0
OS: Darwin x64 21.6.0

@FlowIT-JIT
Copy link

FlowIT-JIT commented May 6, 2024

Probably a duplicate of #209805
Although I'm not sure this covers the issue with the forEach(..) construct.
The problems mentioned by @Jemt also applies to TypeScript. This is completely unacceptable.

@FlowIT-JIT
Copy link

Switching Auto indent to "advanced" makes VSCode usable again:

image

But it's beyond me that 1.88 even shipped with these changes. Completely destroyed the editing experience.

@FlowIT-JIT
Copy link

This is the behaviour with "Auto indent" set to Full:

VSCodeindentationbugs-ezgif com-video-to-gif-converter

I constantly have to fix the code.

@ssigwart
Copy link
Contributor

For those that don't like the new behavior, I created the ssigwart.javascript-typescript-language-configuration extension that will remove the auto-indenting after if, for, and while in JavaScript and Typescript.

@aiday-mar
Copy link
Contributor

aiday-mar commented May 13, 2024

Hi everyone thank you for expressing your concern. This change has come in as a result of the following issue with 43 upvotes (#43244) which precisely asked for indentation to be added after a braceless if/for/while statement. I will explore the idea of adding indentation by default, and then removing it when { is typed.

@aiday-mar aiday-mar assigned aiday-mar and unassigned mjbvz May 13, 2024
@aiday-mar aiday-mar added editor-autoindent Editor auto indentation issues typescript Typescript support issues javascript JavaScript support issues labels May 13, 2024
@rzvc
Copy link
Contributor Author

rzvc commented May 13, 2024

@aiday-mar, hi. Thanks for bringing in more context.

This change has come in as a result of the following issue with 43 upvotes

If you're going by upvotes, this issue has 5 upvotes in a month, while the other one has 43 in 6 years, which is 0.6 likes per month. I would argue that the current fix has created a much bigger problem, so maybe it can be removed until a proper solution is found.

While the previous behaviour was perceived as a shortcoming, the new one is a straight up bug.

@FlowIT-JIT
Copy link

Hi everyone thank you for expressing your concern. This change has come in as a result of the following issue with 43 upvotes (#43244) which precisely asked for indentation to be added after a braceless if/for/while statement. I will explore the idea of adding indentation by default, and then removing it when { is typed.

@aiday-mar Quite frankly, there are hundreds of thousands of people using VSCode, and 43 upvotes were enough to destabilize our primary work tool? This seems like poor judgement. The change should be rolled back immediately.

@photonstorm
Copy link

Please, for the love of all things sane, revert this terrible decision. It makes VSCode an absolute nightmare to work with.

@photonstorm
Copy link

photonstorm commented May 21, 2024

If you hate this change as much as I do, this works:

Uninstall the current broken version and revert to v1.87 https://code.visualstudio.com/updates/v1_87

Then go to File > Preferences > Settings, search for update, and change the automatic update setting to 'none' to prevent the broken version from being downloaded again.

Obviously, this is less than ideal - but I'd much rather stay on this slightly older release than deal with the pain of fixing every single time I use an if or for statement.

@ZLam
Copy link

ZLam commented May 30, 2024

fix it !

@photonstorm
Copy link

photonstorm commented Jun 2, 2024

fix it !

Don't hold your breath. I've a feeling I'm going to be stuck on version 1.87 for at least a year, or more, because of this insane change. An editor should never, ever, dictate a coding style, which is exactly what this change does (perhaps inadvertently while trying to be nice to a small subset of other devs, but that is the end result).

The only exception is if the language demands such structure, such as Python. In all other cases, it should be entirely up to the user.

@photonstorm
Copy link

So happy to see this fixed. How do we easily track when it enters a live release version? As I'm pinned to v1.87 and don't want to turn automatic updates on again until I know this has landed.

@aiday-mar
Copy link
Contributor

aiday-mar commented Jun 20, 2024

The update that has been merged today will be in tomorrow's Insiders release and in next month's stable release :). Next month's stable release should come out around beginning of July

@VSCodeTriageBot VSCodeTriageBot added insiders-released Patch has been released in VS Code Insiders and removed unreleased Patch has not yet been released in VS Code Insiders labels Jun 21, 2024
@aiday-mar aiday-mar added the verification-needed Verification of issue is requested label Jun 24, 2024
@aiday-mar
Copy link
Contributor

To verify:

  • Open a TypeScript or JavaScript file
  • Type if(<some code>) in the file
  • Type Enter, verify the next line is indented
  • Type an opening curly brace {, verify a second closing curly brace is added and we have:
if(<some code>)
{}
  • Press Enter from within the curly braces, verify we have:
if(<some code>)
{
....
}

Here the dots represent the spaces.

@FlowIT-JIT
Copy link

Here the dots represent the spaces.

@aiday-mar That will be a TAB if VSCode is configured to use those instead, right ?

@aiday-mar
Copy link
Contributor

Hi @FlowIT-JIT yes these should be tabs if you configured tabs for the file

@aiday-mar aiday-mar added bug Issue identified by VS Code Team member as probable bug and removed verification-needed Verification of issue is requested labels Jun 24, 2024
@eleanorjboyd eleanorjboyd added the verified Verification succeeded label Jun 25, 2024
@rzvc
Copy link
Contributor Author

rzvc commented Jul 23, 2024

@aiday-mar, thank you. It works when typing, but still presents the issue when pasting.

I have created a new issue for that scenario: #223308.

@vs-code-engineering vs-code-engineering bot locked and limited conversation to collaborators Aug 4, 2024
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 insiders-released Patch has been released in VS Code Insiders javascript JavaScript support issues typescript Typescript support issues verified Verification succeeded
Projects
None yet