Skip to content

Indent when doing line breaks #3284

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

Closed
qubitron opened this issue Nov 9, 2018 · 17 comments
Closed

Indent when doing line breaks #3284

qubitron opened this issue Nov 9, 2018 · 17 comments
Assignees
Labels
area-formatting feature-request Request for new features or functionality

Comments

@qubitron
Copy link

qubitron commented Nov 9, 2018

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

Actual behavior

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

Expected behavior

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

This comment has been minimized.

@DonJayamanne

This comment has been minimized.

@amueller

This comment has been minimized.

@cbrnr
Copy link

cbrnr commented Nov 12, 2018

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

@DonJayamanne
Copy link

This issue was moved to microsoft/python-language-server#385

@DonJayamanne DonJayamanne reopened this Nov 12, 2018
@DonJayamanne DonJayamanne added feature-request Request for new features or functionality needs PR area-formatting labels Nov 12, 2018
@jakebailey
Copy link
Member

I'm pretty sure this isn't a language server problem. The extension tells the editor what to do on enter here:

https://github.com/Microsoft/vscode-python/blob/d0c239fcc78fee9a05713ced15b08e6806affc24/src/client/extension.ts#L121-L140

This is distinct from textDocument/onTypeFormatting.

@DonJayamanne DonJayamanne added needs decision important Issue identified as high-priority needs proposal Need to make some design decisions and removed needs PR labels Nov 12, 2018
@DonJayamanne

This comment has been minimized.

@DonJayamanne DonJayamanne added needs PR and removed important Issue identified as high-priority needs decision needs proposal Need to make some design decisions labels Nov 12, 2018
@jakebailey
Copy link
Member

jakebailey commented Nov 12, 2018

Adding this seems to work (handling comments and ignoring all-whitespace prefixes):

{
    beforeText: /^(?!\s+\\)[^#\n]+\\\s*/,
    action: { indentAction: IndentAction.Indent }
},

continuation_fixed

Tests: https://regex101.com/r/kfNBtR/1

@jakebailey
Copy link
Member

Though, commented out line continuations are syntax errors, so that regex is probably overkill:

  File ".\continuation.py", line 2
    a = 1+  # \
              ^
SyntaxError: invalid syntax

@kevindavenport
Copy link

Would expecting indents after breaking a line of inputs be in the same issue?

subprocess.run(termqry,
shell=True, 
heck=True)

vs

subprocess.run(termqry,
               shell=True,
               check=True)

or is this a simple preference setting?

@cbrnr
Copy link

cbrnr commented Nov 29, 2018

The latter is strongly preferred in the Python community since it is standardized in PEP8. This is also much more important than indentation after a backslash (as in the top example), which almost never happens in Python code. Adding to your example, this would also be the expected behavior:

x = [1, 2, 3,
     4, 5, 6]

and not

x = [1, 2, 3,
4, 5, 6]

So basically it's about how to indent after breaking inside of all kinds of brackets.

@kevindavenport
Copy link

Thank you Clemens, that is helpful. You are right about the brackets, I hope the change goes through.
Do you know how to get the right indenting in what I described via config changes?

@cbrnr
Copy link

cbrnr commented Dec 1, 2018

Currently this is not possible. You can manually indent the second line, which will then correctly indent all subsequent lines. But this is very cumbersome, hence this issue.

@DonJayamanne
Copy link

Will be addressed as part of #481

@jakebailey
Copy link
Member

Reopening to PR in my line continuation rule.

@jakebailey jakebailey reopened this Jan 7, 2019
@jakebailey jakebailey self-assigned this Jan 7, 2019
@ghost ghost removed the needs PR label Jan 15, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Feb 12, 2019
@ericsnowcurrently
Copy link

ericsnowcurrently commented Jun 11, 2019

Prescribed Solution:

There may be a more correct regex to use:

/^(?!\s+\\)[^#\n]+\\$/

See #5821 (comment).

@ghost ghost added the triage-needed Needs assignment to the proper sub-team label Jun 11, 2019
@brettcannon brettcannon added needs PR and removed triage-needed Needs assignment to the proper sub-team feature-* labels Jun 11, 2019
@DonJayamanne DonJayamanne removed this from the 2019, week 1 - Jan Sprint 1 milestone Jun 12, 2019
@karrtikr
Copy link

Closing as fix for #4241 will cover it.

@ghost ghost removed the needs PR label Jun 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-formatting feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests

9 participants