Skip to content

Code formatting doesn't respect user's tabs-vs-spaces preference in "editor.insertSpaces" #530

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

Closed
andrewducker opened this issue Mar 14, 2017 · 14 comments
Labels
Area-Code Formatting Issue-Enhancement A feature request (enhancement).
Milestone

Comments

@andrewducker
Copy link

System Details

  • Operating system name and version: Windows 7
  • VS Code version: 1.10.1
  • PowerShell extension version: 0.9.0
  • Output from $PSVersionTable:
Name                           Value
----                           -----
PSVersion                      4.0
WSManStackVersion              3.0
SerializationVersion           1.1.0.1
CLRVersion                     4.0.30319.42000
BuildVersion                   6.3.9600.16406
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion      2.2

Issue Description

I am experiencing a problem with code formatting.
When the "editor.insertspaces" option is set to false then I would expect the "format selection" option to use tabs for formatting the code. Instead it still used spaces.

@daviwil
Copy link
Contributor

daviwil commented Mar 14, 2017

Hmmm, interesting, I'll investigate.

@daviwil daviwil added the Issue-Bug A bug to squash. label Mar 14, 2017
@daviwil daviwil modified the milestones: 0.10.1, 0.10.2 Mar 14, 2017
@daviwil daviwil modified the milestones: 0.10.2, Next Patch Update Mar 24, 2017
@kapilmb
Copy link

kapilmb commented Mar 29, 2017

The formatter uses only spaces for indentation. We will eventually have the options of using tabs but I am not sure on the timeline for adding it.

@daviwil daviwil modified the milestones: Next Patch Update, Next Feature Update Apr 6, 2017
@andrewducker
Copy link
Author

This means that our code is all being changed from tabs to spaces whenever we edit it, or to a mixture of tabs/spaces, if we use the formatter at all.

Whereabouts is the codebase for the formatter? I'd be up for taking a stab at this myself if nobody else is picking it up.

@kapilmb
Copy link

kapilmb commented May 5, 2017

@andrewducker Allowing vscode to use tabs instead of spaces is definitely something we want to do soon. However, if you want to take a shot at implementing it, you will have to modify the following PSScriptAnalyzer rules.

  • PSPlaceCloseBrace
  • PSPlaceOpenBrace
  • UseConsistentIndentation

We don't have unified way of dealing with tabs/spaces as of yet. You will have to go to each rule and duplicate the tabs/spaces logic. It would however be more preferable to have a unified way of handling tabs/spaces. Not having gotten around to putting such a unified way is the main reason, code formatter is lacking in this choice between tabs and spaces.

@kapilmb kapilmb added Area-Code Formatting Issue-Enhancement A feature request (enhancement). and removed Issue-Bug A bug to squash. labels May 5, 2017
@daviwil daviwil modified the milestones: April 2017, May 2017 May 8, 2017
@wsmelton
Copy link

wsmelton commented May 17, 2017

This is effecting commits to GitHub using VS Code because every file I modify, with just one line, EVERY other line has the tabs converted to spaces. I have to manually issue the convert command to put them back.

Not cool man!

@wsmelton
Copy link

Interesting note, just updated VS Code Insider Edition and this does not seem to be an issue for me now.

@daviwil
Copy link
Contributor

daviwil commented May 17, 2017

Hmmm, not sure why the Insider version would have improved this, but I'll keep an eye out for that!

@daviwil
Copy link
Contributor

daviwil commented May 17, 2017

Demo GIF stolen from Shawn's other issue:

tabsspaces

@daviwil daviwil changed the title Code formatting doesn't respect "editor.insertSpaces": false Code formatting doesn't respect user's tabs-vs-spaces preference in "editor.insertSpaces" May 17, 2017
@daviwil daviwil modified the milestones: June 2017, May 2017 May 17, 2017
@wsmelton
Copy link

This is in Insider Edition, but similar to above with format document it can only effect the previous line or the whole block of code.
tabsspaces_2

@wsmelton
Copy link

wsmelton commented May 18, 2017

Ok, so installed 1.1.0 of PS extension and reloaded window...and above still exist.

@kapilmb
Copy link

kapilmb commented May 18, 2017

@wsmelton Is your formatOnType option set to true ? If that is the case, this behavior, even though not desirable, is expected. This should get fixed once we enable tabs for indentation.

The code formatter indents lines that have language constructs on them. Therefore, for some lines leading tabs get converted to spaces while for others they don't.

@wsmelton
Copy link

wsmelton commented May 19, 2017

@kapilmb it is set to false, default in user settings. That setting annoyed me after trying it so I never use it anymore. I do not explicitly set it to false in my settings.json file though, it just picks up the default.

@kapilmb
Copy link

kapilmb commented May 19, 2017

If formatOnType is set to $false, then this behavior is unexpected. I will dig into the issue to see what is going on here.

What things about formatOnType=$true annoyed you, if you don't mind sharing? Initially when we enabled that feature, the experience was not optimal. But we have been polishing the experience almost every release and I think the experience is decent as of now, but opinions will differ. So, I am very eager to know what can we do to improve the formatOnType=$true experience.

@wsmelton
Copy link

@kapilmb it is strictly personal opinion/preference. If I am typing out code, whether according to my format rules/settings or not, having it change whenever I hit enter just takes my focus off of where my cursor was/is. So strictly a preference for me.

I mean maybe if it paused to format the block of text with a double-enter before actually formatting...I might turn it back on. Consider if you are typing out a script block in PowerShell and not worrying about formatting at the time, just getting it typed out. On average most folks will put two lines between logical sections of code, so if I have an if/else block after I type the end of the else block I will hit enter twice. At that time, or if this could be controlled in some manner as to when it would format as you type?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Code Formatting Issue-Enhancement A feature request (enhancement).
Projects
None yet
Development

No branches or pull requests

4 participants