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

Regression: Code folding regions not detected in R and Python #1908

Closed
jmcphers opened this issue Nov 29, 2023 · 3 comments
Closed

Regression: Code folding regions not detected in R and Python #1908

jmcphers opened this issue Nov 29, 2023 · 3 comments
Assignees
Labels
area: editor Issues related to Editor category.

Comments

@jmcphers
Copy link
Collaborator

jmcphers commented Nov 29, 2023

To reproduce, add some code to a Python file that should be foldable, such as a function definition:

def add_to_path(path):
    import sys

    if path not in sys.path:
        sys.path.insert(0, path)

Attempt to fold the code, either with the keyboard shortcuts (https://code.visualstudio.com/docs/editor/codebasics#_folding) or by hovering over the gutter.

No folding regions are detected, and the code can't be folded. R is similarly affected.

Notes:

  • Code folding is not universally broken; it works in R and Python if you switch to the less-fancy indentation based folding rules (Editor > Folding Strategy).
  • Code folding works using smart features in languages other than R and Python, such as CSS, so this is probably specific to those languages.
Positron Version: 2023.11.0 (Universal) build 1368
Code - OSS Version: 1.84.0
Commit: a71651045484b08ca3f708978761ff1f1072cbc9
Date: 2023-11-29T03:16:22.990Z
Electron: 25.9.2
ElectronBuildId: undefined
Chromium: 114.0.5735.289
Node.js: 18.15.0
V8: 11.4.183.29-electron.0
OS: Darwin arm64 23.1.0
@jmcphers jmcphers added this to the Internal Preview milestone Nov 29, 2023
@wesm wesm added the area: editor Issues related to Editor category. label Feb 29, 2024
@jmcphers
Copy link
Collaborator Author

Reported by a beta user here: https://github.com/posit-dev/positron-beta/discussions/42

@jmcphers jmcphers self-assigned this Apr 25, 2024
@jmcphers
Copy link
Collaborator Author

Oh, here's the problem:

vscode.languages.registerFoldingRangeProvider('*', new CellFoldingRangeProvider()),

The Positron Code Cells extension is registering itself as the folding provider for everything (including R and Python). That means that when it finds no folding ranges in R or Python files, the editor doesn't draw any folding ranges.

Removing the registration on that line fixes the bug.

VS Code is able to blend folding ranges from multiple providers, but in this case what we really want to do is blend the folding range provider's results with the built-in indentation-based folding range provider. As far as I can tell that is not possible with the existing infrastructure.

@juliasilge
Copy link
Contributor

In Positron 2024.04.0 (Universal) build 1576, we now have our code folding back:

code-folding.mov

I can also confirm code folding works for Python. ✅

@petetronic petetronic added support and removed support labels Jul 9, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: editor Issues related to Editor category.
Projects
None yet
Development

No branches or pull requests

4 participants