question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Implement an indentation provider to support folding of docstrings, comments & multi line strings

See original GitHub issue

We might want to consider disabling the folding provider in this release due to a number of issues in VS Code:

Came across this today and found it very annoying. Was unable to collapse a large python file, initially assumed it was an intermittent VSC issue, later looked into this and found that its worse than I suspected.

Basically us introducing a custom folding provider breaks the VSC default folding behavior we won't be able to collapse, any block of Python code

@brettcannon cc

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:84
  • Comments:22 (5 by maintainers)

github_iconTop GitHub Comments

9reactions
beltekylevicommented, Sep 24, 2020

Is there any update or alternative solution for this issue?

6reactions
MicaelJarniaccommented, Nov 24, 2020

I’ve been looking for this as well, and until there’s a better solution, we can use # region and # endregion around the docstring to explicitly inform VS Code that it should be a foldable region. From my testings, it worked pretty well, the docstring was still identified correctly, and all other foldable regions remained intact.

Another option is to use an extension such as https://github.com/zokugun/vscode-explicit-folding that allows us to manually define what should be used to delimit foldable regions, for example with a regex. A problem I’ve had with this one (although I haven’t experimented much) was that it seems to completely replace the foldable regions, and not just add to them, so when I was using it, the only foldable regions I had were the ones between """s, that I manually defined. An example configuration for Python is provided on its readme.

Example with # region and # endregion

def greet(name: str) -> str:
    # region
    """Greets a person

    Parameters
    ----------
    name : str
        Name of the person to greet

    Returns
    -------
    str
        Greetings for said person
    """
    # endregion

    return f"Hello, {name}. Nice to meet you!"
Read more comments on GitHub >

github_iconTop Results From Across the Web

Proper indentation for multiline strings? - python
Docstrings are treated specially: any indent of the first line is removed; the smallest common indent taken over all other non-blank lines is...
Read more >
Proper Indentation for Python Multiline Strings - Finxter
Let's use an example of a long string and see the different methods we have for both creating a multiline string and properly...
Read more >
black · PyPI
Single-character closing docstring quotes are no longer moved to their own line as this is invalid. This was a bug introduced in version...
Read more >
VIM and Python – A Match Made in Heaven
Now you can easily hide portions of your code that you're not currently working on. The initial command, set foldmethod=indent , creates folds...
Read more >
PEP 8 – Style Guide for Python Code
Use 4 spaces per indentation level. Continuation lines should align wrapped elements either vertically using Python's implicit line joining ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found