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

Indentation removed on empty lines when Format Document is used #1980

Open
NorthboundGames opened this issue Jan 25, 2018 · 34 comments
Open

Comments

@NorthboundGames
Copy link

Imgur

VS Code version: Code 1.19.2 (490ef761b76b3f3b3832eff7a588aac891e5fe80, 2018-01-10T15:55:03.538Z)
C# Extension version: 1.13.1

Steps to reproduce

Make multiple new lines in an indented code block, then

  • right click the workspace and choose "Format Document"
  • use FormatOnType, FormatOnPaste, etc., to automatically format the document
  • press Ctrl-Shift-I to auto indent document

Expected behavior

All lines retain their indentation

Actual behavior

Any lines in the document without code have their indentation removed

I have narrowed this down to this plugin, as this behavior isn't seen in VSCode when extension is disabled. I have tried every combination of white space trimming, etc., with no solution.

See Reddit thread.

@akshita31
Copy link
Contributor

Possible duplicate of #1680

@NorthboundGames
Copy link
Author

See text highlighting at end of attached gif, doesn't appear to be caret positioning but actual deletion of the spaces.

@DustinCampbell
Copy link
Member

@poodle-chowder : The goal of the whitespace formatter is to remove superfluous whitespace. So, the behavior that you're seeing where unnecessary indentation at the starts of lines is removed is working as designed. I suspect that the real issue here is really the same as #1680, where the indentation is removed on the line where the caret appears, shifting it to the left.

@NorthboundGames
Copy link
Author

@DustinCampbell Understood. I think the heart of the issue is that whether omnisharp.useEditorFormattingSettings is turned on or off, editor whitespace trimming settings are ignored. With the omnisharp extension disabled, these settings are honored and I don't have the indentation issue.

VS does not seem to consider the indents leading up to a block's indentation level to be superfluous, but VSCode formats to 0 indent even in the middle of a code block. This seems like odd behavior to me. Is the agenda to keep workflow consistent between the two?

@DustinCampbell
Copy link
Member

Not exactly. The intent is to keep the formatting similar for C# between Visual Studio and Visual Studio Code. C#'s formatter has always removed extra indentation, but there's special behavior on the line that the caret is on.

@fizzd
Copy link

fizzd commented Feb 15, 2019

Is there any alternative to format documents without removing whitespace on empty lines now? Or even just a 'format without removing whitespace anywhere at all'? I have tried a lot of solutions and disabling/enabling whitespace trimming settings, but whitespace on blank lines is always deleted.

@Magenda
Copy link

Magenda commented Apr 9, 2019

I've also tried everything but nothing works. Any ideas?

@fizzd
Copy link

fizzd commented Apr 9, 2019

@Magenda Right now i have just accepted writing lines ugly, and then using ctrl-s to immediately format them and put them back at the right position again

@SonOfHans
Copy link

SonOfHans commented May 10, 2019

I would like to have the option to not have whitespace removed on empty lines, regardless of where the caret is located. I frequently leave empty lines between code blocks so as to make my code more readable, oftentimes adding additional code in between these blocks at a later time. Having to re-tab a bunch of times to start that new code is definitely not preferred. This was a feature in VS, and I miss it greatly in VS Code.

@eric-vgastel
Copy link

I've been looking for a solution for weeks. It's driving me literally insane. Please fix this.

@radutomy
Copy link

I, too, would like a solution to this. It's very, very annoying, especially when combined with Vim.

@davidmilligan
Copy link

This bug is infuriating, and nothing has been done about it for years?! The people who maintain this project must not actually use it for real-world, day-to-day work. I don’t see how anyone can stand this behavior. It seems like this issue has just been blamed on some other issue and so nothing is being done about it. Unacceptable people!

@tr0q
Copy link

tr0q commented Aug 14, 2019

I just checked Visual Studio, indeed it deletes whitespaces, it's just it keeps caret on correct indentation level. So it's indeed not an extension fault but VSCode itself.

@wbplomp
Copy link

wbplomp commented Dec 1, 2019

I like empty lines to be removed (with format document) while editing JSON files. Now for some reason this has behavior has been removed.

@geekley
Copy link

geekley commented Jul 17, 2020

This wouldn't be an issue if VSCode had a behavior similar to IntelliJ/Android Studio.
When you go on a blank line (not indented) and press END, it "pretends" to auto-add the whitespace for the correct indentation, and after you type something, it actually adds it for you. So, even though the whitespace is trimmed on blank lines, it's not an annoyance.

@creativogee
Copy link

It's 2020 and there is still no fix to this bug as i am currently experiencing the same issue. I can't believe it. This is literally driving me nuts. One moment it was working the next I know it wasn't.

@nzeman
Copy link

nzeman commented Nov 27, 2020

Any news on this? I cannot switch to VSCode with this. It would drive me insane.

@Phyyl
Copy link

Phyyl commented Mar 2, 2021

I also would like this to be fixed. I really think having "fake" indentation is the way to go.

@JoeRobich
Copy link
Member

I encourage everyone interested in this fuctionality to upvote the following vscode issue - microsoft/vscode#13960

@paweston70
Copy link

I encourage everyone interested in this fuctionality to upvote the following vscode issue - microsoft/vscode#13960

But virtual space is not the same thing - this issue highlights that VS Code is formatting out indents on blank lines...

@cornytrace
Copy link

This is a very annoying problem, and makes interoperability with Visual Studio almost impossible without changing whitespace back and forth in each commit.

@BachiMjavanadze
Copy link

Please fix it

@RandomGgames
Copy link

Please fix!

@IXLLEGACYIXL
Copy link

Still doesnt work

@acdupont
Copy link

acdupont commented Apr 2, 2023

The goal of the whitespace formatter is to remove superfluous whitespace

Is it not arguable that there are reasons to consider indents on empty lines as non superfluous? If it is arguable at all, then there should be a configuration option for it. Forcing one view to be the solution for everyone in all contexts is extremely frustrating.

@victoraldecoa
Copy link

Any chance of prioritizing this? It's a very annoying issue, indeed.

@mana-break
Copy link

When I click on a blank line in Visual Studio (Mac) the caret automatically gets a virtual indent from the previous line. In vscode the caret doesn't get any indentation and I have to press tab several times. It infuriates me. Make it behave like in Visual Studio

@geekley
Copy link

geekley commented Mar 4, 2024

Is it not arguable that there are reasons to consider indents on empty lines as non superfluous?

Yes, it's awful. When I leave blank space between methods in a class, I want to keep it at that class' indentation, so that it's already right when inserting new code. If you think this space is unnecessary, I disagree, and in fact I think removing it is what's not only unnecessary but also counter-intuitive - unless the user explicitly wants to do it this way.

@larrysammii
Copy link

It's been 6 years...
I guess I'm just gonna switch editor.

@geewasvoboda
Copy link

I would also like to see this feature, the auto formatting is basically unusable because of this

@jr-uk
Copy link

jr-uk commented Jun 29, 2024

Finally found a decent simple way with this great extension: https://marketplace.visualstudio.com/items?itemName=jemc.vscode-implicit-indent

@StoneWolf
Copy link

Finally found a decent simple way with this great extension: https://marketplace.visualstudio.com/items?itemName=jemc.vscode-implicit-indent

Be warned that this extension breaks your undo/redo history. If you undo a bunch of edits then move your caret to an empty line, you'll lose all your redo history.

@claybford
Copy link

Any chance this can be prioritized? Bueller?

@JoeRobich
Copy link
Member

JoeRobich commented Aug 12, 2024

This is the VSCode issue tracking Smart Indent, microsoft/vscode#16998.
This is the VSCode issue tracking Virtual Space, microsoft/vscode#13960.

If the feature is meaningful to you, then be sure to let them know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests