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

Configurable folding #772

Open
1 of 4 tasks
weirdan opened this issue Dec 1, 2019 · 12 comments
Open
1 of 4 tasks

Configurable folding #772

weirdan opened this issue Dec 1, 2019 · 12 comments
Labels

Comments

@weirdan
Copy link

weirdan commented Dec 1, 2019

Feature description or problem with existing feature

I would like to be able to configure the following:

  • Fold the last line of the region
  • Fold the docblock together with the element it documents
  • Enable/disable block folding
  • Include (configurable amount of) trailing white-space only lines into the fold

Describe the solution you'd like

Fold the last line of the region

Currently Intelephense omits the last line of the region from the folding range, producing ugly dangling lines at the end of the fold:
image
image

While it may make sense for editors like VSCode that lacks foldtext callbacks, vim/nvim should be able to use more compact folding enhanced by foldtext:
image
image

Even though LSP lacks the facilities to provide the text to show instead of the collapsed region it's not a problem, as it can be done on the client side.

Fold the docblock together with the element it documents

Currently the most compact folded representation for a method with docblock is this:
image
If docblocks were folded with their corresponding code elements it could be futher compacted to:
image
(assuming the dangling line problem is solved as well).

Disable / enable block folding

Block folding (bodies of if, for, etc) is annoying when you have a default folding level set to expand classes but collapse method/properties/consts. Ideally I'd like to be able to configure what should be folded (methods, properties with docblocks, standalone functions, use blocks), and what should be not (blocks). This is how it looks currently with method fold opened:
image
And here's what I would like it to be (note that if/foreach blocks are not folded at all):
image

Include (configurable amount of) trailing white-space only lines into the fold

When you open a class fold, it currently looks like this:
image

I would like to be able to configure it to look like this:
image

This would require empty lines following the method closing brace to be included into the fold.

Additional context

  • Nvim 0.4.3
  • coc.nvim 0.0.74-d83536aa4e
  • coc-phpls 2.1.2
  • Intelephense 1.2.3 premium
@bmewburn
Copy link
Owner

Fold the last line of the region

This one should be straight forward.

Fold the docblock together with the element it documents

I couldn't find documentation on this in LSP but I thought that overlapping ranges were not allowed (in vscode anyway) which poses a problem with this.

Enable/disable block folding

I think this would be better done by the client. The server just sends the ranges and the client can decide what to do about it. LSP has a FoldingRangeKind . IMO more kinds should be added here.

Include (configurable amount of) trailing white-space only lines into the fold

I wonder if this could be bundled into the first point. A setting that folds as much as possible would take care of the dangling lines and whitespace.

@KapitanOczywisty
Copy link
Contributor

I couldn't find documentation on this in LSP but I thought that overlapping ranges were not allowed (in vscode anyway) which poses a problem with this.

https://jsfiddle.net/rp8m92j5/ This could work, just start cannot be the same.

@bmewburn
Copy link
Owner

Comments, Doc blocks and regions now get folded to a single line in 1.5

@bmewburn
Copy link
Owner

Linking microsoft/vscode#70794 which may be relevant to item 2 . Would also need changes to LSP.

@str
Copy link

str commented Jul 11, 2020

Just to confirm if I'm understanding it right, folding from this:

image

to this:

image

is what's currently not possible, right? And it will only be possible with microsoft/vscode#70794, right?

@str
Copy link

str commented Mar 22, 2021

So, I noticed that gitlens shows the documentation from git blame when you are in any line

image

I noticed that this is also shown in a folded docblock

image

Does that mean that it is possible to show the docblock's first line in a folded docblock?

@KapitanOczywisty
Copy link
Contributor

KapitanOczywisty commented Mar 22, 2021

Does that mean that it is possible to show the docblock's first line in a folded docblock?

There isn't any feedback from folding action, so you can show first line after /**, but it will be always visible regardless if block is folded or not.

@AnrDaemon
Copy link

I would really, really like to use structure folding rather than basic indentation folding provided by VS Code.

@weirdan
Copy link
Author

weirdan commented Jul 24, 2023

Even though LSP lacks the facilities to provide the text to show instead of the collapsed region it's not a problem, as it can be done on the client side.

Since LSP 3.17 it's possible for the server to provide the text that is shown instead of the collapsed fold: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#version_3_17_0

I couldn't find documentation on this in LSP but I thought that overlapping ranges were not allowed (in vscode anyway) which poses a problem with this.

Are they overlapping, or rather nested? E.g. the following:

class (line 5)
  method with docblock (line 6)
    docblock (line 6)
    docblock end (line 8)
    method (line 9)
      method signature (line 9)
      method signature end (line 9)
      method body (line 10)
      method body end (line 20)
    method end (line 20)
  method with docblock end (line 20)
class end (line 21)

doesn't look like overlapping ranges to me.

@weirdan
Copy link
Author

weirdan commented Jul 24, 2023

I think this would be better done by the client. The server just sends the ranges and the client can decide what to do about it. LSP has a FoldingRangeKind . IMO more kinds should be added here.

Sounds good to me. FoldingRange.kind is specified as string and is meant to be extendable.

@KapitanOczywisty
Copy link
Contributor

Since LSP 3.17 it's possible for the server to provide the text that is shown instead of the collapsed fold: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#version_3_17_0

Not yet supported in vscode, PR is constantly being postponed microsoft/vscode#170447

Are they overlapping, or rather nested?

They work like nested, because there is no real use-case for overlapping, but in code they are single-level, and you can make them overlap https://jsfiddle.net/n1jd8q9h/

@weirdan
Copy link
Author

weirdan commented Jul 24, 2023

Not yet supported in vscode,

And vim has other means to achieve this, so not a priority for me either. It was more like a note for a potential future feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants