Skip to content

How to use code folding premium feature? #85

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

Closed
zigi05 opened this issue Jan 27, 2023 · 9 comments
Closed

How to use code folding premium feature? #85

zigi05 opened this issue Jan 27, 2023 · 9 comments

Comments

@zigi05
Copy link

zigi05 commented Jan 27, 2023

I have a license and I'd like to use Code folding feature, but cannot find where to set it. Namely I want to have use declarations folded when I open a file.

@rwols
Copy link
Member

rwols commented Jan 27, 2023

Code folding is not supported for this text editor. (Both the server and text editor need to support it)

@rwols
Copy link
Member

rwols commented Jan 27, 2023

Feature request is here sublimehq/sublime_text#3389

@zigi05
Copy link
Author

zigi05 commented Feb 14, 2023

Code folding is not supported for this text editor. (Both the server and text editor need to support it)

But in sublime I can do Edit > Code Folding > Fold to fold any part of the code, or that's now what lsp-intelephense needs for its code folding feature?

@rchl
Copy link
Member

rchl commented Feb 14, 2023

There is no ST API to influence where folder regions should be shown. It can only do it itself based on syntax.

@jwortmann
Copy link
Member

jwortmann commented Aug 8, 2023

I have experimented with this on a branch https://github.com/jwortmann/LSP/tree/fold for the LSP package and created a PR at sublimelsp/LSP#2304. The automatic folding on file open should work™ with that branch if you configure the new setting, e.g.

{
  "initially_folded": ["declaration"],
}

(the setting name is possibly not final), and using the corresponding kind from the server for the declaration ranges ("declaration" is just an example here, you need to find out what kind your server actually uses - it should be possible to see it in the LSP log panel if you look for a response to textDocument/foldingRange, but kind is optional, so it depends on the specific server whether this information is available or not). There are three different kinds predefined in the language server protocol, but servers can also define additional kinds.

And it's only active for newly opened files, i.e. not for the very first file which starts the language server (the intention for this is that parts of the file won't suddenly fold when the file is already open for a few seconds).

The aspect that is not supported by Sublime Text, is to control the folding buttons in the gutter from a plugin. So you will not see any new folding buttons from LSP there.

It's still a pull request / work in progress, so no guarantee that it will become available like this in the next LSP release, but in case you'd like to try it out, any feedback is welcome.

Edit: Assuming "use declarations" in PHP are something like imports, "initially_folded": ["imports"], might work here.

@zigi05
Copy link
Author

zigi05 commented Dec 4, 2023

Thank you @jwortmann, this feature is awesome. Though seems to consume quite a bit of ram.

@jwortmann
Copy link
Member

Thanks, glad that it's useful. But I'm a bit surprised that you experienced higher ram consumption. Iirc there should only be a single request to the server whenever a new file gets opened, and also only one ST API call if applicable. So there is nothing which would run in the background, or on file modifications or similar. And I couldn't imagine that it had any performance impacts. Maybe we should keep an eye on it...

@jfcherng
Copy link
Collaborator

jfcherng commented Dec 5, 2023

Closed since the fold region feature has been implemented on LSP side as stated in #85 (comment). If that's not what's requested, feel free to provide more details and re-open this.

@jfcherng jfcherng closed this as completed Dec 5, 2023
@zigi05
Copy link
Author

zigi05 commented Jun 27, 2024

@jwortmann is it possible to add a setting where you could set a minimum number of declaration lines for the declarations folding to be triggered? For example, when there are only five declaration lines, I don't want them to be folded.

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

No branches or pull requests

6 participants