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

Indent when doing line breaks #3284

Closed
qubitron opened this Issue Nov 9, 2018 · 15 comments

Comments

Projects
None yet
8 participants
@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 was marked as off-topic.

Copy link

amueller commented Nov 10, 2018

duplicate of #481?

@DonJayamanne

This comment was marked as off-topic.

Copy link

DonJayamanne commented Nov 11, 2018

Not a dup

@amueller

This comment was marked as off-topic.

Copy link

amueller commented Nov 11, 2018

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

@cbrnr

This comment has been minimized.

Copy link

cbrnr commented Nov 12, 2018

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

@DonJayamanne

This comment has been minimized.

Copy link

DonJayamanne commented Nov 12, 2018

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

@jakebailey

This comment has been minimized.

Copy link
Member

jakebailey commented Nov 12, 2018

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

// Enable indentAction
// tslint:disable-next-line:no-non-null-assertion
languages.setLanguageConfiguration(PYTHON_LANGUAGE, {
onEnterRules: [
{
beforeText: /^\s*(?:def|class|for|if|elif|else|while|try|with|finally|except|async)\b.*:\s*/,
action: { indentAction: IndentAction.Indent }
},
{
beforeText: /^\s*#.*/,
afterText: /.+$/,
action: { indentAction: IndentAction.None, appendText: '# ' }
},
{
beforeText: /^\s+(continue|break|return)\b.*/,
afterText: /\s+$/,
action: { indentAction: IndentAction.Outdent }
}
]
});

This is distinct from textDocument/onTypeFormatting.

@DonJayamanne

This comment was marked as off-topic.

Copy link

DonJayamanne commented Nov 12, 2018

I'm pretty sure this isn't a language server problem

This was never flagged as a problem of language server. Its flagged as enhancement.

@jakebailey

This comment has been minimized.

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

This comment has been minimized.

Copy link
Member

jakebailey commented Nov 13, 2018

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

This comment has been minimized.

Copy link

kevindavenport commented Nov 29, 2018

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

This comment has been minimized.

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

This comment has been minimized.

Copy link

kevindavenport commented Dec 1, 2018

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

This comment has been minimized.

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

This comment has been minimized.

Copy link

DonJayamanne commented Jan 2, 2019

Will be addressed as part of #481

@jakebailey

This comment has been minimized.

Copy link
Member

jakebailey commented Jan 7, 2019

Reopening to PR in my line continuation rule.

@jakebailey jakebailey reopened this Jan 7, 2019

@jakebailey jakebailey self-assigned this Jan 7, 2019

@jakebailey jakebailey referenced this issue Jan 7, 2019

Merged

Indent on enter after line continuations #3915

6 of 6 tasks complete

DonJayamanne added a commit that referenced this issue Jan 7, 2019

@pvscbot pvscbot removed the needs PR label Jan 15, 2019

@lock lock bot locked as resolved and limited conversation to collaborators Feb 12, 2019

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.