Repository navigation
Smart indentation on separated elements should reuse the prior element's starting base indentation #53548
Description
Activity
- addedDomain: LS: Smart IndentationAutomatic indenting after a newline (not quite formatter/formatting)Automatic indenting after a newline (not quite formatter/formatting)SuggestionAn idea for TypeScriptAn idea for TypeScript
on Mar 27, 2023 DanielRosenwasser commented
on Mar 27, 2023 MemberAuthorMore actionsMaria Solano (@MariaSolOs) had a good suggestion which is that (maybe when there's ambiguity over the previous statement is sufficiently "terminated") we should look for the prior line and check its indentation. If it's "less" than the start indentation of the prior statement (if it exists) then we should reset the indentation to that of the prior statement.
function foo() { let x = 10, y = 20 {| "indentation": 8 } }
function foo() { let x = 10, y = 20 // <- notice no indentation and one presses enter {| "indentation": 4 } }
That way, a user can choose to un-indent themselves.
MariaSolOs commented
on Mar 28, 2023 ContributorMore actionsI debugged this a bit and didn't see any code in the smart indenter being used. Is this not the indentation implementation controlling this Daniel Rosenwasser (@DanielRosenwasser)?
Matt Bierner (@mjbvz) do you know if this indentation behavior is controlled by the "on enter" rules of
language-configuration.json?Reacted by Daniel RosenwasserDanielRosenwasser commented
on Mar 28, 2023 MemberAuthorMore actionsYou're right. I didn't realize it, but TSServer doesn't even provide smart indentation. I guess this change is going to be editor specific.
Reacted by Maria SolanoSmart indentation
But what if I want stupid indentation instead
Reacted by Daniel Rosenwasser and Maria SolanoDanielRosenwasser commented
on Mar 29, 2023 MemberAuthorMore actionsBruce Pascoe (@fatcerberus) you can get that by using any of the examples I provided. 😅
Reacted by Bruce Pascoe and Maria SolanoOn a more serious note, this is definitely something I've noticed in day-to-day. Particularly fun is this case:
if (a && b && c) { // cursor is now here } // <-- automatically added
So now I get to go up a line, press Home twice, Shift+Down three times, Shift+Tab, then finagle the cursor back inside the braces so I can enter my code. It's not a showstopper, but is distracting enough to make me lose my train of thought sometimes.
Full-fat VS tends to handle this much better than VSCode, in general.
MariaSolOs commented
on Mar 30, 2023 ContributorMore actionsBruce Pascoe (@fatcerberus) I would suggest filing an issue in https://github.com/microsoft/vscode for that :)
Maria Solano (@MariaSolOs) I was under the impression that was handled by the same machinery that this issue is about?
MariaSolOs commented
on Mar 30, 2023 ContributorMore actionsBruce Pascoe (@fatcerberus) didn't you say that you only experience that in VS Code?
- addedRescheduledThis issue was previously scheduled to an earlier milestoneThis issue was previously scheduled to an earlier milestone
on Mar 4, 2024
Consider what I'd call some "ideal" smart indentation for the following code samples:
I've specified the "expected" indentation in each of these cases; however, TypeScript today keeps indentation are the same level as the prior line which is wrong. This is especially annoying for the multi-line union case.
There is some ambiguity when one uses an ASI-assuming style though. In these cases, I would personally err on the side of expecting the start indentation.
type Foo =
| "hello"
| "world"
{| "indentation": 0 |}
Then, even for cases where ASI doesn't really apply:
I would say we should pick the start element's base (where
xstarts), since we'll start doing #52899 eventually.