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

Format document inserting 4 spaces instead of 2 #15316

Closed
frankorama opened this issue Nov 10, 2016 · 27 comments
Closed

Format document inserting 4 spaces instead of 2 #15316

frankorama opened this issue Nov 10, 2016 · 27 comments
Assignees
Labels
formatting Source formatter issues info-needed Issue requires more information from poster javascript JavaScript support issues

Comments

@frankorama
Copy link

  • VSCode Version: Code 1.7.1 (02611b4, 2016-11-03T13:46:00.226Z)
  • OS Version: Darwin x64 16.1.0
  • Extensions:
Extension Author Version
prettify-json mohsen1 0.0.3
dust nemesarial 0.0.1

Steps to Reproduce:

  1. open user settings
  2. set "editor.tabSize": 2
  3. "editor.detectIndentation": false
  4. ensure nothing set in workSpace Settings
  5. write some JS code
  6. right-click "Format Document" or alt + shift + F
@aeschli
Copy link
Contributor

aeschli commented Nov 11, 2016

@frankorama What is shown on the VSCode status line?
Formatting which language?

@aeschli aeschli added the info-needed Issue requires more information from poster label Nov 11, 2016
@frankorama
Copy link
Author

UTF-8 LF JavaScript. The file I'm working in has a .js extension.

Some strange behaviour: It seems to be back to 2 spaces now, but when I select all, shift+tab so all the indentation is removed, then right-click "format code", nothing happens.

I thought I had a syntax problem or forgot a semicolon somewhere, but everything looks good. I removed all my comments as well. Same behaviour.

@jedfonner
Copy link

jedfonner commented Nov 15, 2016

I am having this same problem with my .js files. The status line shows "Spaces: 2" but when I Format Document, it changes all my tabs to 4 spaces. I'm using v1.7.1 on OSX.

@frankorama
Copy link
Author

frankorama commented Nov 15, 2016

The problem with the automatic formatting is only happening in VS Code for OSX. I also work on a laptop with Windows 10 and the same .js file formats normally.

@jedfonner
Copy link

This might be related to the JS-CSS-HTML-formatter extension. Removing that extension seems to have solved the problem for me.

See Lonefy/vscode-JS-CSS-HTML-formatter#31

@frankorama
Copy link
Author

I only had DUST language support and JSON prettify extensions installed. Removed them and the formatting is working normally now. Not sure which one was causing the problem though. Should have tested bette.

@dylanparry
Copy link

I am seeing the same issue with Windows 10. It strangely only happens the second time I open a file.

For example, if I open up this:

image

then hit alt + shift + f, the file stays the same with 2-space indentation. If I then close the file, open it up again, and hit alt + shift + f, I get this:

image

The same occurs for .js and .jsx files, but does not happen for .json which I am also formatting with 2-space indentation. It also appears to happen for .ts and .tsx as well—I'm guessing they use the same formatter now?

I have disabled all the extensions I have installed to see if it was any of them causing this, but it does not appear to be the case as disabling them made no difference.

This was referenced Nov 15, 2016
@jrieken
Copy link
Member

jrieken commented Nov 15, 2016

@joaomoreno isn't this what you have seen with TS/JS and reported to them?

@ramya-rao-a ramya-rao-a added the formatting Source formatter issues label Nov 15, 2016
@joaomoreno
Copy link
Member

It could be microsoft/TypeScript#12175

@MagmaRules
Copy link

I'm having exactly the same issue as @dylanparry . OSX 10.11.6 VSCode 1.7.1.

@frankorama
Copy link
Author

I don't know if this helps, but it really is a random problem. I just installed ESLint, JavaScript (ES6) code snippits, and jshint extensions. The formatting function stopped working. I disabled and reenabled the 3 extensions and formatting started working again. Difficult to pinoint exactly which extension is causing the problem because the problem doesn't occur until after a couple of hours of coding sometimes.

@supoved
Copy link

supoved commented Dec 8, 2016

The issue intermittently happens and very often, but only on files that contains ES6 functions notations
() => { ... }
and not affecting
function() { ... }

@maybeec
Copy link

maybeec commented Dec 9, 2016

I am observing this issue as well. Although, I identified no reproducable issue yet, I recognized, that the formatter will internally crash after some time of work. After that it will just use default settings rather than user settings and eventually does not format code at all anymore.

Is there any log, where suppressed issues might be logged to?

After restart it works again for some time.

@waderyan
Copy link

@maybeec if this is a TS / JS issue then it could be showing up in that log. You can see the log in the output window after adding this setting to your user setting:

"typescript.tsserver.trace": "verbose",

If you (and others) could post the output of the log when you see the issue here that would be helpful.

Also if anyone has a workspace that reproduces this issue please post to help us reproduce.

@waderyan waderyan changed the title tabSize 2 in userSettings, but FormatDocument (alt + shift + F) inserting 4 spaces Format document inserting 4 spaces instead of 2 Dec 10, 2016
@maybeec
Copy link

maybeec commented Dec 12, 2016

I enabled the setting and will have a look when the error occurred. So where can I find the log file?

@waderyan
Copy link

If you open the output window the log information is there... I don't know where the log file is actually created... @dbaeumer do you know the location of the TS log file that gets sent to the output window? Maybe the data is not persisted.

@maybeec
Copy link

maybeec commented Dec 13, 2016

Ok basically, I was able to have a view at the output during observation of the error.
However, nothing of interest from tsserver as far as I can see. I save a file and the response comes from format (2566) which indicates to insert whitespaces in front of multiple lines. But there is nothing about format itself, e.g., which config is used.

So what I was observing now is, that this behavior comes up, when having multiple instances of vscode open for some time. After some time, the formatter begins to behave odd

@dbaeumer
Copy link
Member

To get the server log you can use an environment variable to control the location. Something like TSS_LOG="-level verbose -file c:\tmp\server.log"

@dylanparry
Copy link

This seems to be fixed in the latest release, which bundles a new version of TypeScript. Can anyone else confirm this?

@mjbvz mjbvz self-assigned this Jan 31, 2017
@mjbvz
Copy link
Collaborator

mjbvz commented Jan 31, 2017

Yes, I think that TS fixed a number of issues around formatting in 2.1.4 and 2.1.5. Please open a new issue if you still see this problem in VSCode 1.9 using TS 2.1.5+

@mjbvz mjbvz closed this as completed Jan 31, 2017
@xaphod
Copy link

xaphod commented Jun 20, 2017

Happening on vscode 1.13.1 for me on mac os latest, plugins: debugger for chrome 3.1.4, ESLint 1.2.11, React native Tools 0.3.2. Language: JavaScript, UTF-8

@RenaldasK
Copy link

RenaldasK commented Jun 26, 2017

Not fixed, I still have this issue on VSCode 1.13.1 and TS 2.3.0.

UPDATE: In my case the issue was caused by a third party formatting plugin overriding the defaults.

@nariatan
Copy link

Not fixed, still have this issue.
macOS 10.12.6
VS CodeVersion 1.14.2 (1.14.2)

@angularsen
Copy link

Works here with .html files, set Workspace Settings to:

{
    "editor.tabSize": 2,
    "editor.detectIndentation": false
}

Default without either of these were 4 spaces.
1.15.1 on Win10.

@colorpump
Copy link

colorpump commented Oct 19, 2017

edit: solved. (See 2 comments below)

Still have this issue:

  • Windows 10
  • VS Code 1.17.1
  • html file: indent using spaces (4)
  • Workspace Settings:
{
    "editor.tabSize": 4,
    "editor.detectIndentation": false
}

But pressing ALT + SHIFT + F still indented with 2 spaces

@aeschli
Copy link
Contributor

aeschli commented Oct 19, 2017

@colorpump Any extensions enabled related to HTML formatter? Please try without extensions.

To force tabs, use "editor.insertSpaces": false

@colorpump
Copy link

It was my fault.
I had a .editorconfig file in my project as well which overrode my .vscode/settings.json

I'm sorry for confusion

@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 17, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
formatting Source formatter issues info-needed Issue requires more information from poster javascript JavaScript support issues
Projects
None yet
Development

No branches or pull requests