microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
162.93k stars 28.77k forks source link

Fold and Unfold selected code not working in Python #229781

Open ivanlen opened 3 days ago

ivanlen commented 3 days ago

Does this issue occur when all extensions are disabled?: Yes

Steps to Reproduce: "Fold All" and "Unfold All" shortcuts work. They also work if I launch them from Shift+Ctrl+P and write (un)fold All. However when I select a piece of code in the editor and then try to just "Fold" or "Unfold" it is not working.

I tried Pylance and Jedi python servers, and with both of them I am having the same problem. Also by lanuching vscode with all extensions disabled.

  1. Select a piece of code (a whole function for example)
  2. Fold it by Shift+Ctrl+P and then write it "Fold"
  3. Same goes if something is folded and I try to unfold it.

In the Python Language Server output there are no errors or warnings.

Note that this is only happening in python, in json, js other languages it is working fine.

settings.json related to python


    // Python stuff
    "autoDocstring.docstringFormat": "numpy",
    "python.defaultInterpreterPath": "/Users/**/miniconda3/envs/env-testing/bin/python",
    "python.condaPath": "/Users/**/miniconda3/condabin/conda",
    // "python.languageServer": "Pylance",
    "python.languageServer": "Jedi",
    "python.analysis.autoImportCompletions": false,
    "[python]": {
        "editor.semanticHighlighting.enabled": false,
        "editor.formatOnType": true,
        "editor.defaultFormatter": "ms-python.black-formatter"
    },
    "editor.showFoldingControls": "always",
    "python.formatting.provider": "none",
    "python.analysis.typeCheckingMode": "off", // sure?
    // custom formatting for python
    "autopep8.importStrategy": "useBundled",
    "autopep8.showNotifications": "always",
    "autopep8.interpreter": [
        "/Users/**/miniconda3/envs/env-testing/bin/python"
    ],
    "autopep8.args": [
        "--max-line-length",
        "120",
        "--experimental"
    ],
    "black-formatter.showNotifications": "always",
aeschli commented 2 days ago

Fold will collapse the folding range that is at or around the current cursor position. You can see the folding ranges when hovering over the line numbers.

If you don't see any ranges it could be the language server has not returned any. Maybe a syntax error?

ivanlen commented 2 days ago

Hey @aeschli Thanks for the answer. Yes I can see the ranges:

image
ivanlen commented 2 days ago

Is there any log that should provide some info about this that I can check to try to debug the issue. Since it is working for other language and not for python there must be something there.

I can try to see the logs for other languages and compare them with python for example. Maybe you have a better idea.