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

Unexpected indentation behavior after latest update #6886

Closed
mauritshartman opened this issue Aug 7, 2019 · 20 comments
Closed

Unexpected indentation behavior after latest update #6886

mauritshartman opened this issue Aug 7, 2019 · 20 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug regression Bug didn't exist in a previous release

Comments

@mauritshartman
Copy link

mauritshartman commented Aug 7, 2019

Environment data

  • VS Code version: 1.36.1
  • Extension version (available under the Extensions sidebar): 2019.8.29288 (6 August 2019)
  • OS and version: Ubuntu 18.04.1
  • Python version (& distribution if applicable, e.g. Anaconda): 3.6.8
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): N/A
  • Relevant/affected Python packages and their versions: N/A

Expected behaviour

When moving a line up or down (using the editor.action.moveLinesDownAction and editor.action.moveLinesUpAction actions), the following should happen:

  • Line being moved is automatically indented according to the indentation level of its context (i.e. the line(s) above it)
  • The lines surrounding the line being moved, should be unaffected by the line being moved.

Actual behaviour

When moving a line up or down, the indentation levels of the lines surrounding it are wrongfully affected.

Steps to reproduce:

See GIF screenshot below. The Baz class is wrongfully indented one level to the right, when a line was begin moved through it:
indentation

move_to_end


class Foo:
    def __init__(self):
        pass

    def bar(self):
        pass


class Baz:
    pass

Logs

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

User belongs to experiment group 'ShowPlayIcon - start'
> conda --version
> pyenv root
> python3.7 -c "import sys;print(sys.executable)"
> python3.6 -c "import sys;print(sys.executable)"
> python3 -c "import sys;print(sys.executable)"
> python2 -c "import sys;print(sys.executable)"
> python -c "import sys;print(sys.executable)"
> python -c "import sys;print(sys.executable)"
> conda info --json
Starting Jedi Python language engine.
> conda info --json
> conda --version
> /usr/bin/python3 -c "import sys;print(sys.prefix)"
cwd: ~/.vscode/extensions/ms-python.python-2019.8.29288/out/client
> /usr/bin/python3 -c "import sys;print(sys.prefix)"
cwd: ~/.vscode/extensions/ms-python.python-2019.8.29288/out/client
> /usr/bin/python3 -c "import sys;print(sys.executable)"
cwd: ~/.vscode/extensions/ms-python.python-2019.8.29288/out/client
> /usr/bin/python3 -c "import sys;print(sys.executable)"
cwd: ~/.vscode/extensions/ms-python.python-2019.8.29288/out/client
> /usr/bin/python3 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"
cwd: ~/.vscode/extensions/ms-python.python-2019.8.29288/out/client
> /usr/bin/python3 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"
cwd: ~/.vscode/extensions/ms-python.python-2019.8.29288/out/client
> /usr/bin/python3 -m site --user-site
cwd: ~/.vscode/extensions/ms-python.python-2019.8.29288/out/client
> /usr/bin/python3 -m site --user-site
cwd: ~/.vscode/extensions/ms-python.python-2019.8.29288/out/client
> /usr/bin/python3 completion.py
cwd: ~/.vscode/extensions/ms-python.python-2019.8.29288/pythonFiles
> /usr/bin/python3 completion.py
cwd: ~/.vscode/extensions/ms-python.python-2019.8.29288/pythonFiles
> /usr/bin/python3 -m pylint --disable=all --enable=F,unreachable,duplicate-key,unnecessary-semicolon,global-variable-not-assigned,unused-variable,unused-wildcard-import,binary-op-exception,bad-format-string,anomalous-backslash-in-string,bad-open-mode,E0001,E0011,E0012,E0100,E0101,E0102,E0103,E0104,E0105,E0107,E0108,E0110,E0111,E0112,E0113,E0114,E0115,E0116,E0117,E0118,E0202,E0203,E0211,E0213,E0236,E0237,E0238,E0239,E0240,E0241,E0301,E0302,E0303,E0401,E0402,E0601,E0602,E0603,E0604,E0611,E0632,E0633,E0701,E0702,E0703,E0704,E0710,E0711,E0712,E1003,E1101,E1102,E1111,E1120,E1121,E1123,E1124,E1125,E1126,E1127,E1128,E1129,E1130,E1131,E1132,E1133,E1134,E1135,E1136,E1137,E1138,E1139,E1200,E1201,E1205,E1206,E1300,E1301,E1302,E1303,E1304,E1305,E1306,E1310,E1700,E1701 --msg-template='{line},{column},{category},{symbol}:{msg}' --reports=n --output-format=text ~/Desktop/indent.py
cwd: ~/Desktop
> /usr/bin/python3 -m pylint --disable=all --enable=F,unreachable,duplicate-key,unnecessary-semicolon,global-variable-not-assigned,unused-variable,unused-wildcard-import,binary-op-exception,bad-format-string,anomalous-backslash-in-string,bad-open-mode,E0001,E0011,E0012,E0100,E0101,E0102,E0103,E0104,E0105,E0107,E0108,E0110,E0111,E0112,E0113,E0114,E0115,E0116,E0117,E0118,E0202,E0203,E0211,E0213,E0236,E0237,E0238,E0239,E0240,E0241,E0301,E0302,E0303,E0401,E0402,E0601,E0602,E0603,E0604,E0611,E0632,E0633,E0701,E0702,E0703,E0704,E0710,E0711,E0712,E1003,E1101,E1102,E1111,E1120,E1121,E1123,E1124,E1125,E1126,E1127,E1128,E1129,E1130,E1131,E1132,E1133,E1134,E1135,E1136,E1137,E1138,E1139,E1200,E1201,E1205,E1206,E1300,E1301,E1302,E1303,E1304,E1305,E1306,E1310,E1700,E1701 --msg-template='{line},{column},{category},{symbol}:{msg}' --reports=n --output-format=text ~/Desktop/indent.py
cwd: ~/Desktop
> /usr/bin/python3 -c "import pylint"
> /usr/bin/python3 -c "import pylint"
> /usr/bin/python3 -c "import pylint"
> /usr/bin/python3 -c "import pylint"

Linter 'pylint' is not installed. Please install it or select another linter".
Error: Module 'pylint' not installed.

Output from Console under the Developer Tools panel (toggle Developer Tools on under Help; turn on source maps to make any tracebacks be useful by running Enable source map support for extension debugging)

See attached .log file:
[vscode_devtools_console.log](https://github.com/microsoft/vscode-python/files/3476540/vscode_devtools_console.log)


@mauritshartman mauritshartman added triage-needed Needs assignment to the proper sub-team bug Issue identified by VS Code Team member as probable bug labels Aug 7, 2019
@BenoitGielly
Copy link

Got the same issue as well, it breaks my code indentation when moving lines around.
Is there a setting to disable "smart" indentation?

@DonJayamanne DonJayamanne self-assigned this Aug 7, 2019
@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Aug 7, 2019
@kbd
Copy link

kbd commented Aug 7, 2019

I was going to open a new ticket about unexpected indentation behavior, but I think it would be a dupe of this.

The extension now tries to indent consistently with what's above it, which causes errors. Here's a video of the change in behavior between the last version of the extension and current:

python-extension-auto-indent

@aliev
Copy link

aliev commented Aug 8, 2019

I can confirm this too:

out

@faassen
Copy link

faassen commented Aug 8, 2019

I've noticed the same behavior reported by @kbd. In addition and perhaps related, when I paste, the code gets indented inappropriately as well. When you paste a function under another function, the second function is indented to be inside the first function. This place in two steps - the indentation is in the right place first, and then the whole block gets indented. An undo will reach the first step where things are in the right place.

@yankyhoffman
Copy link

I have another version of the bug.
when defining a class or function, the indentation successfully unindents at the line after pass, however the next line reindents

class Foo:
    pass
| # at this line the cursor is where the pipe is
    | # at this line the cursor is where the pipe is

@DonJayamanne DonJayamanne removed their assignment Aug 8, 2019
@DonJayamanne DonJayamanne added triage-needed Needs assignment to the proper sub-team and removed triage labels Aug 8, 2019
@jkyeung
Copy link

jkyeung commented Aug 9, 2019

I'm adding my voice to the chorus. (I'm glad there's a chorus to join!)

Because Python has semantic indentation and no end-block delimiters, it is absolutely critical that the editor doesn't try to be too "smart".

Some of the seemingly new behaviors described in this thread are actually things that VS Code users in general have enjoyed/endured for quite a while now. For example, there's this thread where they discussed the indent-on-paste behavior. It was opened in 2016 and closed in 2017.

In my view, part of the purpose of this extension is to fight against some of the "helpful behaviors" provided by VS Code. What might be genuinely helpful in other languages can actually be actively unhelpful in Python.

Please dumb the indentation back down to where it was! (Or at least provide settings that allow us to choose how dumb we want it.)

@faassen
Copy link

faassen commented Aug 9, 2019 via email

@qyra
Copy link

qyra commented Aug 9, 2019

I have the same problem as kbd, the latest version of the extension indents lines that absolutely should not be indented.

def hello_world(x):
    pass
{Cursor is here}

If you hit "Enter" when your cursor is dedented relative to the previous line, then it will move your cursor in 4 spaces to match the previous line. Which is exactly the opposite of what you want when you are, for instance, adding whitespace after a function definition before writing a new function.

Please just revert this to the previous behaviour (Indent after ':' at the end of a function definition, for loop, and other lines that require an indent immediately after)

@dmahr1
Copy link

dmahr1 commented Aug 9, 2019

Tip for people who are also being driven crazy by this bug: you can easily revert to an older version of the extension by right clicking in the extensions window and choosing "Install another version...". Then pick 2019.6.24221.
image image

I'll update to the newest version once this bug is fixed.

@jkyeung
Copy link

jkyeung commented Aug 9, 2019

Tip for people who are also being driven crazy by this bug: you can easily revert to an older version of the extension by right clicking in the extensions window and choosing "Install another version...".

It's a good tip, thanks for pointing it out. It's just kind of painful for me because 2019.8.29288 fixes #1062 and #4241, and I've been looking forward to those for a long time.

But I think those older problems are probably easier to live with than the current hyperaggressive autoindentation of everything, so yeah, I think I'll be reverting too. :(

@kbd
Copy link

kbd commented Aug 9, 2019

I know @jkyeung I was looking forward to a fix for #4241 for months. It's finally fixed but now auto-indentation is overall worse, doh.

@jkyeung
Copy link

jkyeung commented Aug 9, 2019

I know @jkyeung I was looking forward to a fix for #4241 for months. It's finally fixed but now auto-indentation is overall worse, doh.

Well, in case anyone else is really bothered by #4241, I guess I might as well report that you can go way back in time to before that bug was introduced, and install 2018.12.1 (the first version that exhibits #4241 is 2019.1.0).

@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Aug 12, 2019
@luabud
Copy link
Member

luabud commented Aug 12, 2019

We're really sorry about that. We're going to revert these changes and will let you know once it's out there so you can use the latest update.

@ericsnowcurrently
Copy link
Member

ericsnowcurrently commented Aug 12, 2019

FYI, the related PRs are #6440 (indent after escaped characters) and #6497 (dedent after else, etc.). We should not need to revert #6440 and the "onEnterRules" part of #6497 could probably stay too.

That's assuming the problem is strictly with the "indentationRules" part of the language configuration.

@ericsnowcurrently
Copy link
Member

I was able to verify that using the insiders build everything works correctly now.

@luabud
Copy link
Member

luabud commented Aug 13, 2019

We're going to push a hot fix for this soon, but if anyone would like to try it out ahead of time, you can use the Insiders build (here or by opting-in the Insiders program as a daily basis, more details about it in the blog post)

@michaelkolber
Copy link

We're going to push a hot fix for this soon, but if anyone would like to try it out ahead of time, you can use the Insiders build (here or by opting-in the Insiders program as a daily basis, more details about it in the blog post)

^ With links

@luabud
Copy link
Member

luabud commented Aug 13, 2019

🤦‍♀️ sorry about that, and thank you so much @michaelkolber

@pzelnip
Copy link

pzelnip commented Aug 15, 2019

Is there an ETA on when this will be released? I'd rather not opt-in to the insiders build, and I definitely don't want to downgrade.

@kbd
Copy link

kbd commented Aug 15, 2019

It's already released.
https://twitter.com/pythonvscode/status/1161415401374277632

@lock lock bot locked as resolved and limited conversation to collaborators Aug 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug regression Bug didn't exist in a previous release
Projects
None yet
Development

No branches or pull requests