microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
163.59k stars 29.03k forks source link

Arrow function indenting curly braces when starting next line #216737

Open djoodew opened 4 months ago

djoodew commented 4 months ago

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

Steps to Reproduce:

  1. In Javascript/Typescript, create an arrow function. Curly braces should start on the following line, instead of on the same line as the function definition.

https://github.com/microsoft/vscode/assets/50113193/371dcb0f-143f-4927-913d-9eabe5ebbc4c

  1. The curly braces are indented an extra level.
vscodenpa commented 4 months ago

Thanks for creating this issue! It looks like you may be using an old version of VS Code, the latest stable release is 1.90.2. Please try upgrading to the latest version and checking whether this issue remains.

Happy Coding!

djoodew commented 4 months ago

Hi, yes the issue still remains now that I'm on the latest version

KyleKolander commented 3 months ago

This is happening for me in TypeScript files after if conditions, too.

aiday-mar commented 3 months ago

Hi thank you for posting this issue @djoodew . So from what I understood, you mean the issue is that the next line should not be indented after an arrow of an arrow function?

So a fix has been merged recently to outdent the next line if an opening curly brace is type. The fix is in the latest Insiders release and should be in the next stable release. The new behavior would be as follows:

https://github.com/microsoft/vscode/assets/61460952/888e5ac2-a03c-4cbc-ab17-edb9c1188459

Hi @KyleKolander thank you for the comment. I suppose you are talking about braceless if statements. This change came from the issue https://github.com/microsoft/vscode/issues/43244 which amassed 44 votes. As in the case above, the next line is outdent is an opening curly brace is typed:

https://github.com/microsoft/vscode/assets/61460952/61f47f7a-c6d9-43c1-9200-30268223d84b

KyleKolander commented 3 months ago

I am, and I left a comment there. This is terrible. You guys need to fix this. People expect the standard behavior. Very confusing and frustrating. I'm shocked...

aiday-mar commented 3 months ago

The behavior we have introduced is the same as in certain other editors. As I mentioned when you type an opening curly brace the line is now outdented, so you end up with the following sequence of code:

if() 

Press Enter ->

if()
...

Type { ->

if()
{}

Press Enter from within {} ->

if()
{
....
}

What indentation behavior would you expect?

KyleKolander commented 3 months ago

I expect that the curly braces will be aligned with the start of the if.

// bad - how it works now
if ()
    {
        ...
    }

// good - how it always used to work
if ()
{
    ....
}

This is how it works now, which is not how it used to work.

vscode_outdent_wrong

image

Even started it with all extensions disabled code --disable-extensions.

aiday-mar commented 3 months ago

Hi @KyleKolander yes like I said previously in my message in the other thread which you commented on, you do not see the fix and the correct behavior yet because you are on the latest stable VS Code release, and the fix is not there yet. To see the fix you have to wait until the next stable release which should come out this week or next week. You can also see the fix already now in the Insiders VS Code release which comes out every single day and can be downloaded here: https://code.visualstudio.com/insiders/.