You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Case 3 is fixed by #385
Case 1 is a matter of taste. TypeScript or C# don't auto-indent to arguments. Also, some people prefer their own continuation rules - by opening brace, by first letter, by comma as in this style
print(a
, b
Case 2 requires AST analysis and extension currently has no facilities for this.
Case 1 is a matter of taste. TypeScript or C# don't auto-indent to arguments
Really? That's surprising to me. I'm so used to such indentation in vim and I find it very natural to have. Think about it: you're inside parenthesis, typing function arguments. Why would you not want to have an indentation, at least any of the two? It's a continuation of a function call and we always indent them, aren't we?
Guess this is why VS has options to configure how these things get formatted
Could you please direct me to such configuration? I looked through the VSCode settings filtering them by "indent" and "format" and only found this relevant option: "editor.autoIndent": true,.
Case 2 requires AST analysis and extension currently has no facilities for this.
Are there any plans to add such facilities? Maybe this case could be moved out into a separate issue so that you could keep it on your backlog if it's not possible to implement it with the current facilities?
Yuri Bochkarev (@balta2ar) - it depends on the language and I meant big VS IDE. C# simple preserves user indentation of arguments. By default it indents one level deeper and not by ( or first argument
In R there is setting
Yes, there are plans to have AST analysis, but this is pretty big work item. Working on it :-)
Tree-sitter is a C library for incremental parsing, intended to be used via bindings to higher-level languages. It can be used to build a concrete syntax tree for a program and efficiently update the syntax tree as the program is edited. This makes it suitable for use in text-editing programs
I haven't tried it in practice myself yet, but it sounds promising from the description. Just spreading the word :-)
I commented on the existing issue. Having syntactic correct indent would be great. Ideally the stylistic ones would also work, though; I think that's basic pep8 that people that don't even know about pep8 instinctively follow.
I commented on the existing issue. Having syntactic correct indent would be great. Ideally the stylistic ones would also work, though
One thing at a time. 😉 Ultimately it's up to the Pylance team to decide how far they want to take this, but I'm personally supportive of them do simple, reasonable stylistic formatting as long as people realize they will very likely not get knobs to tweak anything (I would argue you should be using a formatter in that case).
Reacted by Richard Höchenberger and Andreas Mueller
FYI if you are not getting automatic indentation with Pylance by turning on formatOnType, we think it might be a bug. Please try the pre-release version of Pylance to see if that fixes it for you.
So I go to the command palette and open user settings and change the editor.formatOnType to true, then I close the editor, open it again, check the settings and I see:
That seems odd. I'm also on v2023.1.11 now.
Depending on how I open and close editor windows that seems to be non-deterministic though (I could reproduce several times, now I can't reproduce).
I still don't get the de-indent for else.
It seems we had a bug in the Python extension that wasn't automatically opting people into the feature when formatOnType was explicitly set. We are planning to do a point release today that should hopefully fix this for our stable users, but if you are using the latest pre-release build of the Python extension as of yesterday it should fix it for you.
There was a red squiggle but I didn't see a warning. Not sure if my description was clear: I copy & pasted the setting, saved it, closed VSCode, opened VSCode, open the settings, and now my settings were clearly invalid JSON.
Andreas Mueller (@amueller) sorry -- would you mind confirming if you still see this using v2023.1.10111008 of the Python extension? I was able to reproduce this with an older version, but it does no longer happen for me with the newest ones:
We merged #20480 n the Python extension a couple of days ago, which we believe has the fix for the problem you're seeing.
There was a red squiggle but I didn't see a warning. Not sure if my description was clear: I copy & pasted the setting, saved it, closed VSCode, opened VSCode, open the settings, and now my settings were clearly invalid JSON.
This was part of the bug that was fixed. We are pushing a point release today that should fix this in stable while it was fixed in our pre-release a few days ago.
After switching to the insider version I was able to install v2023.1.10111008 and I don't see the removal of the config flag any more, and the as-you-type indentation of else works as expected. Thank you all for your help!
We have enabled format on type for all Python files by default when using Pylance. For those who want to disable this behaviour, you can add the following setting to your settings file (View > Command Palette... > Preferences: Open User Settings (JSON)):
"[python]": {
"editor.formatOnType": false
}
If you have any problems or feedback, please open a separate issue at the Pylance repo detailing the behaviour you'd like to see 😊
Activity
balta2ar commentedon Jan 6, 2018
Added case 3.
balta2ar commentedon Jan 8, 2018
Case 3 actually has been reported in #385.
MikhailArkhipov commentedon Feb 1, 2018
Case 3 is fixed by #385
Case 1 is a matter of taste. TypeScript or C# don't auto-indent to arguments. Also, some people prefer their own continuation rules - by opening brace, by first letter, by comma as in this style
Case 2 requires AST analysis and extension currently has no facilities for this.
DonJayamanne commentedon Feb 1, 2018
Agreed. Guess this is why VS has options to configure how these things get formatted.
balta2ar commentedon Feb 1, 2018
Really? That's surprising to me. I'm so used to such indentation in vim and I find it very natural to have. Think about it: you're inside parenthesis, typing function arguments. Why would you not want to have an indentation, at least any of the two? It's a continuation of a function call and we always indent them, aren't we?
Could you please direct me to such configuration? I looked through the VSCode settings filtering them by "indent" and "format" and only found this relevant option:
"editor.autoIndent": true,.Are there any plans to add such facilities? Maybe this case could be moved out into a separate issue so that you could keep it on your backlog if it's not possible to implement it with the current facilities?
DonJayamanne commentedon Feb 1, 2018
May be i was wrong, I just assumed this was one of the settings. Could be something in Reshparer. Either way I could be mistaken.
MikhailArkhipov commentedon Feb 6, 2018
Yuri Bochkarev (@balta2ar) - it depends on the language and I meant big VS IDE. C# simple preserves user indentation of arguments. By default it indents one level deeper and not by ( or first argument
In R there is setting
Yes, there are plans to have AST analysis, but this is pretty big work item. Working on it :-)
balta2ar commentedon Feb 6, 2018
That's great! Thanks for giving a heads up! Oh, and speaking of AST. There is no doubt you know how to do it right, but I noticed this comment today: atom/atom#13877 (comment)
There is this thing https://github.com/tree-sitter/tree-sitter:
I haven't tried it in practice myself yet, but it sounds promising from the description. Just spreading the word :-)
MikhailArkhipov commentedon Feb 6, 2018
I can ensure you we have lots of parsers here at MS :-).
77 remaining items
amueller commentedon Dec 27, 2022
I commented on the existing issue. Having syntactic correct indent would be great. Ideally the stylistic ones would also work, though; I think that's basic pep8 that people that don't even know about pep8 instinctively follow.
brettcannon commentedon Jan 3, 2023
One thing at a time. 😉 Ultimately it's up to the Pylance team to decide how far they want to take this, but I'm personally supportive of them do simple, reasonable stylistic formatting as long as people realize they will very likely not get knobs to tweak anything (I would argue you should be using a formatter in that case).
brettcannon commentedon Jan 6, 2023
FYI if you are not getting automatic indentation with Pylance by turning on
formatOnType, we think it might be a bug. Please try the pre-release version of Pylance to see if that fixes it for you.drorata commentedon Jan 6, 2023
I switched to the pre-release (v2023.1.11), I have:
{ "[python]": { "editor.formatOnType": true }, "python.languageServer": "Pylance" }in my
.vscode/settings.json, and it still doesn't work.I'm still seeing the
testenvironment that I mentioned in microsoft/vscode-jupyter#12501 - It might be related.amueller commentedon Jan 9, 2023
So I go to the command palette and open user settings and change the

editor.formatOnTypetotrue, then I close the editor, open it again, check the settings and I see:That seems odd. I'm also on v2023.1.11 now.
Depending on how I open and close editor windows that seems to be non-deterministic though (I could reproduce several times, now I can't reproduce).
I still don't get the de-indent for
else.amueller commentedon Jan 9, 2023
ok open and closed settings again and it was gone again (this time without the comma for some reason)
brettcannon commentedon Jan 10, 2023
It seems we had a bug in the Python extension that wasn't automatically opting people into the feature when
formatOnTypewas explicitly set. We are planning to do a point release today that should hopefully fix this for our stable users, but if you are using the latest pre-release build of the Python extension as of yesterday it should fix it for you.brettcannon commentedon Jan 10, 2023
The trailing comma makes it invalid JSON, so there should have been a red squiggle and a warning that your settings were invalid.
amueller commentedon Jan 11, 2023
There was a red squiggle but I didn't see a warning. Not sure if my description was clear: I copy & pasted the setting, saved it, closed VSCode, opened VSCode, open the settings, and now my settings were clearly invalid JSON.
luabud commentedon Jan 11, 2023
Andreas Mueller (@amueller) sorry -- would you mind confirming if you still see this using v2023.1.10111008 of the Python extension? I was able to reproduce this with an older version, but it does no longer happen for me with the newest ones:

We merged #20480 n the Python extension a couple of days ago, which we believe has the fix for the problem you're seeing.
brettcannon commentedon Jan 11, 2023
This was part of the bug that was fixed. We are pushing a point release today that should fix this in stable while it was fixed in our pre-release a few days ago.
amueller commentedon Jan 11, 2023
After switching to the insider version I was able to install
v2023.1.10111008and I don't see the removal of the config flag any more, and the as-you-type indentation ofelseworks as expected. Thank you all for your help!luabud commentedon May 10, 2023
We have enabled format on type for all Python files by default when using Pylance. For those who want to disable this behaviour, you can add the following setting to your settings file (View > Command Palette... > Preferences: Open User Settings (JSON)):
If you have any problems or feedback, please open a separate issue at the Pylance repo detailing the behaviour you'd like to see 😊