vscode icon indicating copy to clipboard operation
vscode copied to clipboard

editor.formatOnType breaks indentation

Open nelsonlaquet opened this issue 10 years ago • 15 comments

This is for version 0.10.10, when writing JavaScript.

It appears that setting "editor.formatOnType" to true breaks indentation when you add a newline. What I mean by this is that if you are at the end of a line, and hit "enter", the keyboard cursor will briefly appear at the right indentation level on the new line, but snap back to the line start after about 100 milliseconds.

Setting formatOnType to false fixes this behavior; but, of course, VS Code will no longer format on type. Perhaps whatever code formatter is being used is configured to remove all indentation for empty lines.

The only other custom setting that I have is setting "insertSpaces" to false.

nelsonlaquet avatar Mar 08 '16 01:03 nelsonlaquet

I have the same issue

massimocode avatar Mar 08 '16 14:03 massimocode

Same issue, really annoying.

johnwu5 avatar Mar 08 '16 19:03 johnwu5

@dbaeumer I will take a look to see if I can "tweak" the format edit if it wants to remove whitespace around the cursor

alexdima avatar Mar 08 '16 21:03 alexdima

@alexandrudima this is a problem with the tsserver and IMO we should push the TS team to fix this. The corresponding issue in TS land is: https://github.com/Microsoft/TypeScript/issues/6700

dbaeumer avatar Mar 09 '16 08:03 dbaeumer

Same issue :+1:

nsgundy avatar Mar 15 '16 15:03 nsgundy

@dbaeumer Is this fixed on the TS side on master?

I still get it in some cases such as pressing Enter twice:

formatontype

alexdima avatar Mar 17 '16 17:03 alexdima

@alexandrudima it should be fixed and @jrieken and I tested it (I updated the tsserver to 1.8.9 today). But it looks like not all cases are fixed. I opt for opening a issue against TS.

dbaeumer avatar Mar 17 '16 19:03 dbaeumer

What's the status regarding that today ?

skol-pro avatar Mar 29 '16 14:03 skol-pro

It's a little big fixed... The true issue is in TypeScript-land and we have refrained from massaging their text edits. @alexandrudima tracks the issue on the TypeScript-side, tho unsure what the status is?

jrieken avatar Mar 29 '16 17:03 jrieken

I have to say the formatOnType function is always broken. In most vscode versions , it doesn't work properly. Everytime vscode updated, I turned it on, then some minutes I had to turn it off. I suggest you turn on this option by default like visual studio,and you may pay more attention on his.

heroboy avatar Apr 18 '16 03:04 heroboy

The fix for Microsoft/TypeScript#6700 is in the nightly TypeScript build.

Until VS code adopts a new version you can use a newer version of TypeScript by:

Install the new typescript version globally:

  • npm install -g typescript@next
  • in the user settings define "typescript.tsdk": "path to your folder/node_modules/typescript/lib"

Install the new typescript version locally into your workspace:

  • npm install -g typescript@next
  • code will pick it up from there.

The version of the install TypeScript version is shown in the status bar at the right.

egamma avatar Apr 26 '16 07:04 egamma

I still have the problem that @alexandrudima described. Using Version 1.1.0-insider (1.1.0-insider) and [email protected].

apr -28-2016 09-07-43

4kochi avatar Apr 28 '16 07:04 4kochi

That does look like the problem wasn't fixed yet. Thanks for the repo, I'll keep looking.

zhengbli avatar Apr 28 '16 21:04 zhengbli

Clearing the milestone, since it is an upstream fix that is planned by another team.

egamma avatar May 02 '16 14:05 egamma

@dbaeumer added a workaround for this on our side in PR #6911

alexdima avatar May 27 '16 09:05 alexdima