Skip to content

Weird code folding in Jupyter notebooks #2988

@hamdanal

Description

@hamdanal

Summary

Folding ranges in Jupyter notebook are sometimes messed up and do not align with indented blocks, parentheses, etc.

This is the minimal example I could get with a notebook containing two cells:

  • repro.ipynb Cell 1
import os
import zipfile

out_dir = "output"
archive = "archive.zip"  # <-------------------------------------- FOLDS HERE!

with zipfile.ZipFile(archive, "r") as zip_ref:  # <--------------- NO FOLD HERE!
    for file_info in zip_ref.infolist():  # <--------------------- NO FOLD HERE!
        out_path = os.path.join(out_dir, file_info.filename)
        if file_info.file_size == 0:
            pass
        else:  # <------------------------------------------------ NO FOLD HERE!
            if os.path.exists(out_path):  # <--------------------- NO FOLD HERE!
                pass
  • repro.ipynb Cell 2
x1 = X(
    p1="X",
)

x2 = X(
    p1="X",
    p2="X",
    p3="X",
    p4="X",
    p5="X",  # <-------------------------------------- FOLDS HERE!
    p6="X",
    p7="X",
)
Demo

Image

Version

ty server version: 0.0.21

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingnotebooksupport for Jupyter (or similar) notebooksserverRelated to the LSP server

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions