Python-language-server: Indent when doing line breaks

Created on 12 Nov 2018  路  13Comments  路  Source: microsoft/python-language-server

_From @qubitron on November 9, 2018 20:23_

Feedback from twitter here: https://twitter.com/amuellerml/status/1060895092230291457

Actual behavior

a = 1 + \
<--- indent is here

Expected behavior

a = 1 + \
    <--- indent is here

_Copied from original issue: Microsoft/vscode-python#3284_

Most helpful comment

btw I think the cases in Microsoft/vscode-python#481 are more important since using / for line-continuation is discouraged:
https://www.python.org/dev/peps/pep-0008/#maximum-line-length

All 13 comments

_From @amueller on November 10, 2018 20:55_

duplicate of #481?

Not a dup

_From @amueller on November 11, 2018 1:1_

Hmm I guess this is a separate case that's not listed?

_From @cbrnr on November 12, 2018 8:5_

481 is certainly related because it also concerns proper PEP8-style indentation.

Are you sure this is a language server issue? IIRC the extension is the one in control of indent on enter via those hardcoded regexes in extension.ts.

Doesn't LS handle this via format on type?
How else would the LS resolve https://github.com/Microsoft/vscode-python/issues/481

No. On type formatting is not enabled by default, and will only affect the previous line (the one you hit enter from). Without the language server enabled:

continuation

If the "correct" behavior is to indent after a line continuation, then I think that first regex in onEnterRules needs to be modified.

The only sort of indention that the LS does is the : block formatter, which is a 1:1 port from the extension and does do the extra indent. I think it's only done in on-type because onEnterRules isn't powerful enough.

It could technically be done inside of the onTypeFormat handler, but it would need to be reimplemented in the extension too (and then wouldn't be available to most people, because most people don't enable on-type).

Sorry, I take that back, the : formatter is triggered on : (duh), so doesn't involve the onEnterRules, because : isn't \n. Brainfart.

Ok, I'm confused, is this something that the language server can handle or not?

It _could_ handle it, but it shouldn't. All of the rules on when to add an indent on an enter are produced by those onEnterRules, which IIRC is the standard way in VSC to implement it per-language, and will apply to all users, not just those who change the editor-wide formatOnType setting.

Adding a one-off exception _could_ be done, but would then need to be reimplemented in the extension's line formatter too. And IMO, this sort of auto-indent is not the same thing as on-type formatting.

btw I think the cases in Microsoft/vscode-python#481 are more important since using / for line-continuation is discouraged:
https://www.python.org/dev/peps/pep-0008/#maximum-line-length

Was this page helpful?
0 / 5 - 0 ratings