sublimelsp / LSP-intelephense

PHP support for Sublime's LSP plugin provided through intelephense.
MIT License
96 stars 3 forks source link

How to use code folding premium feature? #85

Closed zigi05 closed 11 months ago

zigi05 commented 1 year ago

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 commented 1 year ago

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

rwols commented 1 year ago

Feature request is here https://github.com/sublimehq/sublime_text/issues/3389

zigi05 commented 1 year ago

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 commented 1 year ago

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

jwortmann commented 1 year ago

I have experimented with this on a branch https://github.com/jwortmann/LSP/tree/fold for the LSP package and created a PR at https://github.com/sublimelsp/LSP/pull/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 commented 11 months ago

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

jwortmann commented 11 months ago

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 commented 11 months ago

Closed since the fold region feature has been implemented on LSP side as stated in https://github.com/sublimelsp/LSP-intelephense/issues/85#issuecomment-1669023569. If that's not what's requested, feel free to provide more details and re-open this.

zigi05 commented 4 months ago

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