sublimelsp / LSP-intelephense

PHP support for Sublime's LSP plugin provided through intelephense.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to use code folding premium feature?

zigi05 opened this issue · comments

commented

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.

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

Feature request is here sublimehq/sublime_text#3389

commented

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?

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

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.

commented

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

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...

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.