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 dedent else in an if..else block not working if user is not in experiment #20479

Closed
rchiodo opened this issue Jan 4, 2023 · 13 comments
Closed
Assignees
Labels
area-intellisense LSP-related functionality: auto-complete, docstrings, navigation, refactoring, etc. bug Issue identified by VS Code Team member as probable bug needs PR Ready to be worked on

Comments

@rchiodo
Copy link

rchiodo commented Jan 4, 2023

Discussed in https://github.com/microsoft/pylance-release/discussions/3804

Originally posted by drorata December 22, 2022

Following the request from #481 by @brettcannon

Environment data

  • Language Server version: v2022.12.20
  • OS and version: macos 13.1
  • Python version (& distribution if applicable, e.g. Anaconda): 3.11

Code Snippet

if __name__=="__main__":
    print("foo")  # 1
else:  # 2
    pass

After No.1, typing else starts right below the p. Once else: is typed, the editor doesn't de-intent the line and I have to do it manually.

Repro Steps

  1. Create a new file and start typing.

Expected behavior

The else: is supposed to be de-indented one level.

Actual behavior

else: stays below the previous line (which belongs to the if part)

de-indent-bug-vscode

Logs

Experiment 'pythonaacf' is active
Experiment 'pythonSurveyNotificationcf' is active
LSP Notebooks experiment is enabled
LSP Notebooks interactive window support is enabled
Python interpreter path: ~/.poetry_envs/foo-cv-BPVTkgqj-py3.11/bin/python
> poetry env list --full-path
cwd: .
> ~/.pyenv/versions/3.10.4/bin/python ~/.vscode/extensions/ms-python.python-2022.20.1/pythonFiles/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2022.20.1/pythonFiles/interpreterInfo.py
> ~/.pyenv/versions/3.11.1/bin/python ~/.vscode/extensions/ms-python.python-2022.20.1/pythonFiles/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2022.20.1/pythonFiles/interpreterInfo.py
> conda info --json
> ~/.pyenv/versions/3.7.13/bin/python ~/.vscode/extensions/ms-python.python-2022.20.1/pythonFiles/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2022.20.1/pythonFiles/interpreterInfo.py
> ~/.pyenv/versions/3.9.13/bin/python ~/.vscode/extensions/ms-python.python-2022.20.1/pythonFiles/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2022.20.1/pythonFiles/interpreterInfo.py
> . ~/.poetry_envs/foo-cv-BPVTkgqj-py3.11/bin/activate && echo 'e8b39361-0157-4923-80e1-22d70d46dee6' && python ~/.vscode/extensions/ms-python.python-2022.20.1/pythonFiles/printEnvVariables.py
> ~/.poetry_envs/username-cv-lqqRfM4F-py3.11/bin/python ~/.vscode/extensions/ms-python.python-2022.20.1/pythonFiles/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2022.20.1/pythonFiles/interpreterInfo.py
> ~/.poetry_envs/fast-api-sql-example-hJw5i7sx-py3.11/bin/python ~/.vscode/extensions/ms-python.python-2022.20.1/pythonFiles/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2022.20.1/pythonFiles/interpreterInfo.py
> ~/.poetry_envs/foo-cv-BPVTkgqj-py3.11/bin/python ~/.vscode/extensions/ms-python.python-2022.20.1/pythonFiles/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2022.20.1/pythonFiles/interpreterInfo.py
> ~/.poetry_envs/kumsitz-lib-iVmOjJvt-py3.10/bin/python ~/.vscode/extensions/ms-python.python-2022.20.1/pythonFiles/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2022.20.1/pythonFiles/interpreterInfo.py
> ~/.poetry_envs/pyspark-playground-Dg6oNfQx-py3.10/bin/python ~/.vscode/extensions/ms-python.python-2022.20.1/pythonFiles/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2022.20.1/pythonFiles/interpreterInfo.py
> ~/.poetry_envs/stocks-playground-bIdRsd_o-py3.10/bin/python ~/.vscode/extensions/ms-python.python-2022.20.1/pythonFiles/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2022.20.1/pythonFiles/interpreterInfo.py
> /usr/bin/python3 ~/.vscode/extensions/ms-python.python-2022.20.1/pythonFiles/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2022.20.1/pythonFiles/interpreterInfo.py
> /opt/homebrew/bin/python3 ~/.vscode/extensions/ms-python.python-2022.20.1/pythonFiles/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2022.20.1/pythonFiles/interpreterInfo.py
> /opt/homebrew/bin/python3.11 ~/.vscode/extensions/ms-python.python-2022.20.1/pythonFiles/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2022.20.1/pythonFiles/interpreterInfo.py
> ~/.local/share/virtualenvs/test-project-GV0hGqPR/bin/python ~/.vscode/extensions/ms-python.python-2022.20.1/pythonFiles/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2022.20.1/pythonFiles/interpreterInfo.py
[ERROR 2022-11-23 8:14:35.526]: [Error: Command failed: /Users/username/.local/share/virtualenvs/test-project-GV0hGqPR/bin/python /Users/username/.vscode/extensions/ms-python.python-2022.20.1/pythonFiles/get_output_via_markers.py /Users/username/.vscode/extensions/ms-python.python-2022.20.1/pythonFiles/interpreterInfo.py
/bin/sh: /Users/username/.local/share/virtualenvs/test-project-GV0hGqPR/bin/python: No such file or directory

	at ChildProcess.exithandler (node:child_process:408:12)
	at ChildProcess.emit (node:events:526:28)
	at maybeClose (node:internal/child_process:1092:16)
	at Socket.<anonymous> (node:internal/child_process:451:11)
	at Socket.emit (node:events:526:28)
	at Pipe.<anonymous> (node:net:687:12)] {
  killed: false,
  code: 127,
  signal: null,
  cmd: '/Users/username/.local/share/virtualenvs/test-project-GV0hGqPR/bin/python /Users/username/.vscode/extensions/ms-python.python-2022.20.1/pythonFiles/get_output_via_markers.py /Users/username/.vscode/extensions/ms-python.python-2022.20.1/pythonFiles/interpreterInfo.py'
}
Starting Pylance language server.
Extension search path: /Users/username/.vscode/extensions
> ~/.poetry_envs/foo-cv-BPVTkgqj-py3.11/bin/python ~/.vscode/extensions/ms-python.python-2022.20.1/pythonFiles/linter.py -p flake8 /opt/homebrew/bin/flake8 --max-line-length=120 ./foo_cv/__init__.py
cwd: .
##########Linting Output - flake8##########


> ~/.local/share/virtualenvs/test-project-GV0hGqPR/bin/python ~/.vscode/extensions/ms-python.python-2022.20.1/pythonFiles/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2022.20.1/pythonFiles/interpreterInfo.py
[ERROR 2022-11-23 8:14:37.540]: [Error: Command failed: /Users/username/.local/share/virtualenvs/test-project-GV0hGqPR/bin/python /Users/username/.vscode/extensions/ms-python.python-2022.20.1/pythonFiles/get_output_via_markers.py /Users/username/.vscode/extensions/ms-python.python-2022.20.1/pythonFiles/interpreterInfo.py
/bin/sh: /Users/username/.local/share/virtualenvs/test-project-GV0hGqPR/bin/python: No such file or directory

	at ChildProcess.exithandler (node:child_process:408:12)
	at ChildProcess.emit (node:events:526:28)
	at maybeClose (node:internal/child_process:1092:16)
	at ChildProcess._handle.onexit (node:internal/child_process:302:5)] {
  killed: false,
  code: 127,
  signal: null,
  cmd: '/Users/username/.local/share/virtualenvs/test-project-GV0hGqPR/bin/python /Users/username/.vscode/extensions/ms-python.python-2022.20.1/pythonFiles/get_output_via_markers.py /Users/username/.vscode/extensions/ms-python.python-2022.20.1/pythonFiles/interpreterInfo.py'
}
> /opt/homebrew/bin/black --diff --quiet ./foo_cv/__init__.py.fcaa6f612d7121d453663cbc59080266.tmp
cwd: .
Extension search path: /Users/username/.vscode/extensions
> ~/.poetry_envs/foo-cv-BPVTkgqj-py3.11/bin/python ~/.vscode/extensions/ms-python.python-2022.20.1/pythonFiles/linter.py -p flake8 /opt/homebrew/bin/flake8 --max-line-length=120 ./foo_cv/__init__.py
cwd: .
##########Linting Output - flake8##########


> ~/.poetry_envs/foo-cv-BPVTkgqj-py3.11/bin/python ~/.vscode/extensions/ms-python.python-2022.20.1/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir . -s --cache-clear tests
cwd: .

I don't really know what is test-project-GV0hGqPR nor where is it coming from. Maybe that's a hint for the problem.

@rchiodo
Copy link
Author

rchiodo commented Jan 4, 2023

This actually seems to be working for me. When typing the ':' it works.
elsededent

@rchiodo
Copy link
Author

rchiodo commented Jan 4, 2023

@drorata what are your user settings?

They should have these:

  "[python]": {
    "editor.formatOnType": true
  },
  "python.languageServer": "Pylance",

@rchiodo rchiodo self-assigned this Jan 4, 2023
@drorata
Copy link

drorata commented Jan 5, 2023

I have just added in a workspace the settings suggested by @rchiodo and restarted VScode. Then I recorded the following:

Screen.Recording.2023-01-05.at.08.42.55.mov

So, it doesn't seem to do the trick...

@rchiodo
Copy link
Author

rchiodo commented Jan 5, 2023

I wonder if something else is taking over formatting. What other extensions do you have installed?

@drorata
Copy link

drorata commented Jan 5, 2023

Is there a way to exctarct a full list of installed extensions?

@rchiodo
Copy link
Author

rchiodo commented Jan 5, 2023

From the command line:

code --list-extensions

It'd probably be better to just disable everything, then reenable python and pylance and see if it works. Because I'm not going to be able to tell that something else has a format on type provider just by looking at the list.

@drorata
Copy link

drorata commented Jan 6, 2023

I tried to disable all extensions and then enable "Python" + "Pylence". Note that a few other extensions were enabled as well by doing so (e.g. Jupyter related). In any case, this didn't solve the problem.

The installed extensions are:

bierner.markdown-mermaid
bpruitt-goddard.mermaid-markdown-syntax-highlighting
bungcip.better-toml
christian-kohler.path-intellisense
eamodio.gitlens
gera2ld.markmap-vscode
hediet.vscode-drawio
IronGeek.vscode-env
James-Yu.latex-workshop
kenhowardpdx.vscode-gist
mechatroner.rainbow-csv
ms-azuretools.vscode-docker
ms-python.isort
ms-python.python
ms-python.vscode-pylance
ms-toolsai.jupyter
ms-toolsai.jupyter-keymap
ms-toolsai.jupyter-renderers
ms-toolsai.vscode-jupyter-cell-tags
ms-toolsai.vscode-jupyter-slideshow
ms-vscode-remote.remote-containers
ms-vscode-remote.remote-ssh
ms-vscode-remote.remote-ssh-edit
ms-vscode-remote.remote-wsl
ms-vscode-remote.vscode-remote-extensionpack
ms-vscode.remote-explorer
njpwerner.autodocstring
PKief.material-icon-theme
rebornix.ruby
redhat.vscode-yaml
stkb.rewrap
streetsidesoftware.code-spell-checker
vstirbu.vscode-mermaid-preview
wholroyd.jinja
wingrunr21.vscode-ruby
yzhang.markdown-all-in-one

@karrtikr
Copy link

karrtikr commented Jan 6, 2023

@rchido curious, is this behind an experiment or available to all users?

@rchiodo
Copy link
Author

rchiodo commented Jan 6, 2023

@rchido curious, is this behind an experiment or available to all users?

We discussed this yesterday in standup and it might be affected by an experiment. It isn't listed here:

image

But @luabud thought it might be enabled with just a flag somewhere else. I don't see it in any of our package.jsons though.

@drorata can you try setting this flag and see if it has any effect?

  "python.experiments.optInto": [
    "All"
  ]

That should turn on whatever experiment may be making this not work.

At least if I do the opposite, it stops working for me:

  "python.experiments.optOutFrom": [
    "All"
  ]

@rchiodo
Copy link
Author

rchiodo commented Jan 6, 2023

Thanks @luabud, it looks like this code here is the culprit:

return inExperiment && formatOnTypeEffectiveValue;

This only works if the user is in the experiment too. Switching this to the python repository, That code should be checking if it gets the default value or if the user supplied it and only using the experiment value if the user didn't supply it.

@rchiodo
Copy link
Author

rchiodo commented Jan 6, 2023

@drorata That means my workaround should fix your issue:

  "python.experiments.optInto": [
    "All"
  ]

@rchiodo rchiodo transferred this issue from microsoft/pylance-release Jan 6, 2023
@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Jan 6, 2023
@rchiodo rchiodo changed the title Auto dedent else in an if..else block Auto dedent else in an if..else block not working if user is not in experiment Jan 6, 2023
@drorata
Copy link

drorata commented Jan 8, 2023

I added

"python.experiments.optInto": [
    "All"
  ]

to my users settings.json and now it works as expected.

FWIW, I still can see the strange virtual environment as discussed in microsoft/vscode-jupyter#12501.

@karthiknadig karthiknadig added bug Issue identified by VS Code Team member as probable bug area-intellisense LSP-related functionality: auto-complete, docstrings, navigation, refactoring, etc. needs PR Ready to be worked on and removed triage-needed Needs assignment to the proper sub-team labels Jan 9, 2023
@luabud
Copy link
Member

luabud commented Jan 9, 2023

This should be fixed on our pre-release version, so it should work without the "python.experiments.optInto" setting as well!

@luabud luabud closed this as completed Jan 9, 2023
karthiknadig pushed a commit to karthiknadig/vscode-python that referenced this issue Jan 11, 2023
karthiknadig added a commit that referenced this issue Jan 11, 2023
For #20479

Another fix for recovery release.

Co-authored-by: Luciana Abud <45497113+luabud@users.noreply.github.com>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-intellisense LSP-related functionality: auto-complete, docstrings, navigation, refactoring, etc. bug Issue identified by VS Code Team member as probable bug needs PR Ready to be worked on
Projects
None yet
Development

No branches or pull requests

5 participants