-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Making auto indentation work #8996
Comments
If you have any questions about my code let me know. Be sure to also check out https://github.com/DSpeckhals/python-indent-parser/blob/master/src/index.ts for the heavy lifting on the parsing side (library written by @DSpeckhals with contributions from me). It should be pretty thoroughly documented. |
@kbrose Yes, thank you.
Can you recall about cases where extension unexpectedly is overriding what your extension is doing? We would want to correct that. |
Hey there! VSCodeVim relies on the Is there any chance you could define Happy to discuss and/or help out with this. Thanks for the great extension! |
@J-Fields If you browse through the mentioned issues, we used to have As |
This is now supported by Pylance so closing this. If anyone still faces an issue with this, feel free to open up an issue on https://github.com/microsoft/pylance-release. |
As noted in spike #8669
There are three approaches to solve this:
1.
VSCode Language ConfigurationVSCode provides
OnEnterRules
andindentationRules
which dedents/indents the block given the previous line matches the regex. But regexes can't be used to cover every case, and the current rules are not powerful enough. microsoft/vscode#66235Also sometimes just knowledge of previous line is not sufficient to make a decision on the indent.
2.
On-type indentingWhen
editor.formatOnType
is set totrue
, one can intervene in between when a user types and indent accordingly. We currently use this inonEnterFormatter.ts
and other places. We can use this to cover all the cases one by one. But on-type formatting is not enabled by default nor is very popular (and enables a slew of formatting rules other than cursor alignment), so forcing users to enable on-type formatting as a whole would be good to avoid.3.
Add a key binding for enterWe can add something like
(may need more modifying)
and use that to intervene. This way we don't need to have
editor.formatOnType
enabled. However we need to keep in mind that in this case we're responsible for cursor alignment after the user presses enter, otherwise cursor would stay where it is.As there is no progress on vscode upstream issues related to
1.
,going with3.
makes the most sense at this point.https://github.com/kbrose/vsc-python-indent/blob/master/src/indent.ts seems like a wonderful place to take help from. It covers most cases (#481) we currently have open issues for and is well documented. We can use npm package
python-indent-parser
similarly to the way @kbrose does.Also another thing to note here is that having both language configuration and key bindings can override each other sometimes. So we should be moving away from regexes when we solve work items for this.
EDIT: We've decided to go with
2.
Work items
editor.formatOnType
totrue
by default when using python language.onEnterFormatter.ts
to support only indenting. (onTypeIndenting
)languageConfiguration.ts
to.json
.Cut down regexes in language configuration so that it doesn't conflict withonTypeIndenting
.languageConfiguration.ts
may conflict withonTypeIndenting
. If you can identify such conflicts, turn off rules inlanguageConfiguration.ts
wheneditor.formatOnType
is set totrue
.Improve auto-indentation behaviour #481 (function call)
Meta issue for formatting #684 (meta issue)
Create unit tests for auto indentation #1314 (tests)
async for
andasync with
are not automatically indenting #7344 (async for
andasync with
)Unexpected indentation behavior after latest update #6886 (moving a line breaks things)
Indent when doing line breaks #3284 (trailing slash)
Auto indent else inside if block #16105 which was introduced when we removed the
onEnterFormatter.ts
whenonType
formatting is on.Note we also do dedenting when user presses semi-colon : https://github.com/Microsoft/vscode-python/blob/3c7bb774519ebf5aed91f90e10c7b8dd0fc567ec/src/client/typeFormatters/blockFormatProvider.ts#L25
Make sure these does not conflict with what Kbrose's extension is doing.
The text was updated successfully, but these errors were encountered: