formatOnType does not respect current line indendtiation
From @isidorn on January 26, 2016 15:50
- js workspace, have salsa enabled
- "editor.formatOnType": true
- The format on type is too aggrressive and does not respect current indentiation. This is especially noticable when trying to create object literals
- if salse is disabled this works nicely
Copied from original issue: Microsoft/vscode#2377
@isidorn I can't see any weirdness. Can you please provide some steps. I tested ts and js and they behave the same. Both honoring indent setting.
Please be aware that if a indent of for example 4 spaces exist and you have insert tab and tab size > 4 then format on type from TS will stil insert 4 spaces to align the code correctly.
From @isidorn on January 28, 2016 15:23
var t = {
name: isidor,
// this line gets indented all the way to the start once I press enter after name property
}
Same happens for TS.
I debugged it and this is a tsserver behavior. When pressing enter after Isidor, VSCode inserts the right indention but the tsserver returns and edit that deletes that indention. IMO the tsserver should be smart and if Isidor is ended with , adjust the indention since there is a high likelihood that the user inserts another property.
Sounds like this is a general issue with TypeScript also, not a Salsa issue.
Does this also remove the space after function keyword like below? Our lint rules require space after function. But after latest vs code 0.10.10 it removes spaces on reformatting ...
var test = function() { };
@mlakmal This issue is referring to the "format on enter" feature; the issue you are referring to is different. Though it may worth opening another issue for tracking.
Another related issue, when adding comments as below example:

Prior to 0.10.10 a space is added after the * in next new line when pressing Enter. In 0.10.10, the space is removed, CMD-Z will bring it back.
@egamma is the issue 3796 in vs code related to this issue...
The formatter never removed spaces from comments. i think this is the editor doing this. @egamma any thoughts?
@mhegazy Is there any progress on this? We have multiple customers complaining about format on typing being usable.
@jrieken do you have more information about this issue? are there other cases? i can not reproduce the original issue.
See https://github.com/Microsoft/vscode/issues/3797 and https://github.com/Microsoft/vscode/issues/5656#issuecomment-214190434
This issue was already fixed by #7307, for some reason I forgot to close this issue. The fix is in the nightly versions now, and will release with 2.0.
@zhengbli Can you please comment on https://github.com/Microsoft/vscode/issues/3797#issuecomment-215330505
does not look like it is fixed.
from https://github.com/Microsoft/vscode/issues/3797#issuecomment-215330505

@dbaeumer @jrieken
I am testing a fix, however I found that it may have something to do with VSCode's own formatting behavior.
For example, when I have the formatOnType set to true, I observed this:

While the VSCode log said:
Sending request: change (76). Response expected: no. Current queue length: 0
Arguments: {
"file": "c:/Users/lizhe/Documents/playground/testLocalFormatting/test.ts",
"line": 1,
"offset": 35,
"endLine": 1,
"endOffset": 35,
"insertString": "\r\n "
}
Sending request: formatonkey (77). Response expected: yes. Current queue length: 0
Arguments: {
"file": "c:/Users/lizhe/Documents/playground/testLocalFormatting/test.ts",
"line": 2,
"offset": 5,
"key": "\n"
}
Response received: formatonkey (77). Request took 3 ms. Success: true
Result: [
{
"start": {
"line": 1,
"offset": 16
},
"end": {
"line": 1,
"offset": 17
},
"newText": ""
},
{
"start": {
"line": 1,
"offset": 31
},
"end": {
"line": 1,
"offset": 32
},
"newText": ""
}
]
Sending request: change (78). Response expected: no. Current queue length: 0
Arguments: {
"file": "c:/Users/lizhe/Documents/playground/testLocalFormatting/test.ts",
"line": 2,
"offset": 1,
"endLine": 2,
"endOffset": 5,
"insertString": ""
}
Sending request: change (79). Response expected: no. Current queue length: 0
Arguments: {
"file": "c:/Users/lizhe/Documents/playground/testLocalFormatting/test.ts",
"line": 1,
"offset": 31,
"endLine": 1,
"endOffset": 32,
"insertString": ""
}
Sending request: change (80). Response expected: no. Current queue length: 0
Arguments: {
"file": "c:/Users/lizhe/Documents/playground/testLocalFormatting/test.ts",
"line": 1,
"offset": 16,
"endLine": 1,
"endOffset": 17,
"insertString": ""
}
It looks like the server is returning a correct change, while VSCode decides to delete the spaces on the second line. Is there any way to turn off VSCode's formatting for testing purpose?
Indeed the TypeScript language service getIndentationAtPosition on that line gives the right result as I use it in alm:

But as you can tell from the comments I struggled to get it just right originally because of my misconfigurings and stuff :) :rose:
@alexandrudima Can you comment?