Skip to content
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

Auto-indent behavior as before / jumping to beginning of line #3781

Closed
amueller opened this issue Dec 21, 2022 · 5 comments
Closed

Auto-indent behavior as before / jumping to beginning of line #3781

amueller opened this issue Dec 21, 2022 · 5 comments
Assignees
Labels
bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version

Comments

@amueller
Copy link

amueller commented Dec 21, 2022

Filing as requrested in microsoft/vscode-python#481

Environment data

  • Language Server version: v2022.12.20
  • [Info - 5:13:28 PM] (8596) Pylance language server 2022.12.20 (pyright 621d886b) starting
  • OS and version: Windows / WSL
  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.8.13 via anaconda

image

Code Snippet

def f(a,<newline>

jumps to the beginning of the next line, instead of to the opening parenthesis indentation.
Same in similar settings (calling a function, in an if clause, ...), and also if the parenthesis is closed.

I added the languageServer line and the "editor.formatOnType": true, but still see the linebreak behavior issues.
Is there a way to confirm I set it up correctly?

@amueller amueller changed the title Auto-indent behavior as before Auto-indent behavior as before / jumping to beginning of line Dec 21, 2022
@judej judej added the needs investigation Could be an issue - needs investigation label Jan 3, 2023
@rchiodo
Copy link
Contributor

rchiodo commented Jan 4, 2023

I believe this is on purpose. Until the function has a : on the end, it's not considered a function. Auto indentation only happens once it's known to be a function (or an if statement, etc).

This works:

def f(a):<newline>

But this doesn't:

def f(a)<newline>

@rchiodo rchiodo closed this as completed Jan 4, 2023
@amueller
Copy link
Author

amueller commented Jan 4, 2023

please note that there is no closing parenthesis in my example, meaning the next token would be a second argument for the function, not the function body.

@rchiodo
Copy link
Contributor

rchiodo commented Jan 4, 2023

This does seem silly. Why would it not indent to the parens. PEP 8 seems to indicate a different default than jumping to the ( though:

https://peps.python.org/pep-0008/#indentation

Maybe that's just an example though.

If we were to implement this would it need settings?

@rchiodo rchiodo reopened this Jan 4, 2023
@amueller
Copy link
Author

amueller commented Jan 4, 2023

image

My reading (and I think what flake8 and pep8 enforce?) is that if there is nothing after the opening parenthesis (handing indent), we indent an extra level, if there is already something after the opening parenthesis (first example), then indent to the opening delimiter.

@PylanceBot PylanceBot added the fixed in next version (main) A fix has been implemented and will appear in an upcoming version label Jan 6, 2023
@heejaechang
Copy link
Contributor

This issue has been fixed in prerelease version 2023.1.21, which we've just released. You can find the changelog here: CHANGELOG.md

@judej judej added enhancement New feature or request bug Something isn't working and removed needs investigation Could be an issue - needs investigation enhancement New feature or request labels Jan 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version
Projects
None yet
Development

No branches or pull requests

5 participants