basedpyright icon indicating copy to clipboard operation
basedpyright copied to clipboard

support `textDocument/foldingRange`

Open igorlfs opened this issue 2 years ago • 13 comments

LSP Spec: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_foldingRange

Other servers that implement this capability are rust-analyzer and tsserver.

  • [ ] function definitions
  • [ ] class definitions
  • [ ] docstrings
  • [ ] if statements
  • [ ] for loops
  • [ ] imports

igorlfs avatar Apr 17 '24 17:04 igorlfs

are these folding ranges? if so, vscode seems to add these on its own without pylance/pyright installed:

image

just to make sure we're on the same page, are you using a different editor and want this feature added to the language server?

DetachHead avatar Apr 17 '24 23:04 DetachHead

Yep, those are the folds!

I assume VS Code has a built-in implementation for some languages, or something like that.

I'm using neovim, which also provides a "default" implementation, but having as it language server capability would be nice. Some servers allow folding imports / comments, for instance.

igorlfs avatar Apr 18 '24 01:04 igorlfs

alright, i just removed "pylance feature parity" because as far as i can tell the functionality doesn't come from pylance but vscode itself

DetachHead avatar Apr 18 '24 01:04 DetachHead

I do think the capability comes from pylance, see this issue

igorlfs avatar Apr 18 '24 01:04 igorlfs

Can we automatically fold the import blocks, PyCharm does this and it's very appreciated: I don't like seeing 1000 lines of generated code at the top of every file

KotlinIsland avatar Apr 18 '24 01:04 KotlinIsland

I do think the capability comes from pylance, see this issue

Folding support was added in 2022.1.1

https://github.com/microsoft/pylance-release/issues/372#issuecomment-1023726101

KotlinIsland avatar Apr 18 '24 01:04 KotlinIsland

currently (in bpr) folding is based on indentation:

def foo():
    print(
)
    print(2)

Try this out, you will observe that it is broken.

KotlinIsland avatar Apr 18 '24 01:04 KotlinIsland