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

Options for automatic indentation #19303

Closed
Krzysztof-Cieslak opened this issue Jan 24, 2017 · 20 comments
Closed

Options for automatic indentation #19303

Krzysztof-Cieslak opened this issue Jan 24, 2017 · 20 comments
Assignees
Labels
editor-autoindent Editor auto indentation issues feature-request Request for new features or functionality
Milestone

Comments

@Krzysztof-Cieslak
Copy link
Contributor

Krzysztof-Cieslak commented Jan 24, 2017

Automatic indentation currently coming out of the box with VSCode is really unhelpful in any white-space significant programming language.

Twitter discussion (F#): https://twitter.com/isaac_abraham/status/824035064807731201
Problem reported in Python plugin: https://github.com/DonJayamanne/pythonVSCode/issues/666
Example behavior in F# (notice how new errors are shown after this automatic formatting):
ident

As far as I understand this behavior can be controlled using IndentationRules in LanguageConfiguration but:

  1. They are RegEx based which won't allow us to create accurate behavior.
  2. Default behaviour is completely wrong on any white-space significant language.

I think it would be good to add option to disable this behavior.

@isaacabraham
Copy link

"good option", more like "must have". This is driving me crazy.

@forki
Copy link

forki commented Jan 25, 2017

brackets

@mousetraps
Copy link
Contributor

Oh no! Looks frustrating - sorry about that! @rebornix and @alexandrudima to the rescue!

@mousetraps mousetraps added editor bug Issue identified by VS Code Team member as probable bug labels Jan 25, 2017
@alexdima
Copy link
Member

Fixed via b1c8dad

@alexdima alexdima added this to the January 2017 milestone Jan 25, 2017
@forki
Copy link

forki commented Jan 25, 2017

wait a second. Did you add a fix for the concrete issues or did you allow us to disable it completely? Because I think we really need the second one.

@alexdima
Copy link
Member

That fix targets a different issue similar in nature, and the fix is that typing a closing bracket will not change the current line's indentation if the bracket is preceded by any non-whitespace characters, covering both issues exemplified in the two gifs in this thread.

Tomorrow's insiders build will contain the change and it would be great if you could try it out and provide additional feedback. We can then proceed to reopen this issue or start a new one, as you prefer.

@isaacabraham
Copy link

@alexandrudima I really think having the ability to turn the auto-format off is important. Not everyone wants it.

@forki
Copy link

forki commented Jan 25, 2017 via email

@forki
Copy link

forki commented Jan 25, 2017

brackets

there are millions of new edge cases to find...

@rebornix
Copy link
Member

@forki are you using the Stable version? The one you just mentioned is fixed in Insider.

I can see why you want to have the option to turn off this feature. Right now when there is an indentation adjustment, it's triggered by one of the following:

  • EnterRules
  • Electric Char
  • Indentation Rules
  • Extensions ...

The first two were implemented first to provide a reasonable experience with brackets and later we introduced Indentation Rules as other editors do. Indentation rules are not silver bullet, they can't make the indentation perfect as they are just talking about limited number of lines around.

Our target is not making indentation rules perfect as that's not possible but we want to make it reasonable. For users who want to make the indentation correct always, a proper formatter which reads AST can actually help, for example gfmt for Go. But there are a large amount of users who don't want to have the formatters as they are too heavy, they may just want the editor to provide a reasonable indentation but nothing else.

This iteration we enhanced Format with formatOnPaste and improved regex based indentation rules at the same time. We have options for Format so of course it's a good idea to have options for Auto Indentation. Like I said at the beginning, it's a valid feature request.

For anyone who is interested in this area, you may want to take a look at #17868 and PRz are always welcome.

@rebornix rebornix reopened this Jan 26, 2017
@rebornix rebornix changed the title Automatic indentation behavior Options for automatic indentation Jan 26, 2017
@rebornix rebornix added feature-request Request for new features or functionality and removed bug Issue identified by VS Code Team member as probable bug labels Jan 26, 2017
@forki
Copy link

forki commented Jan 26, 2017

Yes I'm on the released bits. Regarding indentation: just moving everything 4 (or 2 depending on project) chars to the right on tab would be the 100% correct solution for us. No need for ast or any other heuristic.

@alexdima
Copy link
Member

@forki @isaacabraham @Krzysztof-Cieslak

Can you please try out the latest insider that went out a few hours ago? And provide concrete examples of what is not working as expected. Thank you!

@alexdima alexdima modified the milestones: Backlog, January 2017 Jan 26, 2017
@alexdima alexdima removed their assignment Jan 26, 2017
@isaacabraham
Copy link

Here's one.
test

@isaacabraham
Copy link

Another similar one: -
test

@isaacabraham
Copy link

I can confirm that some of the other cases that I see on the mainline build are fixed on the insider build. But I still think you should allow people to turn this off - people might use a formatting style you don't cater for, or simply not want it at all.

@gandhis1
Copy link

gandhis1 commented Jan 27, 2017

Let me know if this is unrelated, but I see a similar issue with Python as I reported in https://github.com/DonJayamanne/pythonVSCode/issues/666

image

Edit: Just realized this was already referenced by OP.

@forki
Copy link

forki commented Jan 27, 2017 via email

@gandhis1
Copy link

gandhis1 commented Jan 27, 2017

I tested this on the latest insider, and it appeared to be fixed.

Although my question would be now, is when you have an open bracket expression that has yet to be closed, and you press enter, why the default behavior is not to indent to the parenthesis location.

@peredin
Copy link

peredin commented May 22, 2017

I definitely want to be able to disable any automatic indentation completely.

As it is now, if I'm at the end of a line <tab><tab>void foo(); and press enter VScode will automatically add <tab><tab> to the next line which for me is anything but helpful.

Tested in both the latest Insiders build and 1.12.2.

@rebornix
Copy link
Member

rebornix commented Nov 3, 2020

editor.autoIndent setting is now enriched to allow you disable this feature completely.

@rebornix rebornix closed this as completed Nov 3, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Dec 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
editor-autoindent Editor auto indentation issues feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests

8 participants