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
Add textDocument/foldingRange capability to LSP client #14306
base: master
Are you sure you want to change the base?
Conversation
I have a few questions:
|
Just out of curiosity, doesn't this have the same problem as we at nvim-treesitter have with tree-sitter folding, that we can only fold on LSP/tree-sitter buffers but foldexpr/foldmethod is a window option and the window might switch to a non-LSP/tree-sitter buffer. |
The fold information is stored with the buffer number of the buffer the |
This is the issue I was referring to. But this is rather an inherent problem of |
Couldn't we add an autocommand or something to change the fold method based on buffer id? I guess the solution would be to make foldmethod buffer local in the long term. |
What should that look like exactly? One possibility would be to add an option for the user to make these options generally window local or buffer local. This would be compatible and keep the behavior consistent, but also a somewhat strange option to have. Or do you mean that it should only be buffer local if LSP folding is used? One could also add "lsp" as a possible value to |
So what should I do next; should I explicitly request a review and if so, how? |
Maybe since @tjdevries is assigned to the issue, can you review my code or otherwise direct me? |
I'm ok merging this with the limitations of foldmethod in mind, but I think we should create a new tracking issue for a buffer local implementation of foldmethod. We could hypothetically unmap foldexpr on BufLeave. Basically the logic would be: if BufLeave, set up an autocmd on BufEnter that unmaps the foldexpr for the window if the same language server is not attached to the window. |
@mjlbach I'm done then, could you merge it please? I've been happily using this feature for almost a year now but it would be great if I could have this without having to keep maintaining my fork. |
Let me tag Mathias for review, I think the logic looks ok. I'm a little bit concerned about:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think at the very least this would require some tests.
But I'm also not sure if it is good to add 4 new public methods to the API. Ideally it would only expose the foldexpr and keep the remainder private.
Not entirely sure how to make that happen. foldexpr
could keep a cache internally and make a sync request the first time + register some autocmds to keep it updated async afterwards.
Or depending on how often the foldexpr gets evaluated maybe it is even feasible to make sync requests all the time if the buffer got dirty inbetween?
And I think we should consider adding a buflocal foldexpr first to solve the mentioned issues with the window based foldexpr.
Couldn't the user put your workaround into their
Is there a preferred way for how I should deal with such conflicts?
Do you have an alternative suggestion for how to achieve the folds being updated once the response is received? How would you feel about the aforementioned possibility of an |
Could you point me to where I would implement such tests? I can't find the tests for the other LSP handlers in the codebase.
I think the user should be able to explicitly trigger document folding requests via
In my experience making sync requests with
See my previous comment. Does this mean no extensions or changes to any part of neovim's folding mechanisms should be suggested before this issue is solved or in what way is this PR particularly affected by it? |
Most of the tests for the lsp module are in
I'm not sure if it wouldn't be surprising that
This is currently the case to some degree, but we're trying to reduce that as people end up using this functions and are then unhappy if we later change them.
I suspected as much. That was the reason why I mentioned the caching.
No it doesn't mean that - but it means that we shouldn't merge something that we know has flaws which in the worst case may require breaking changes later on. |
Is there a tracking issue for making foldexpr/foldmethod buffer-local? I'd possibly be interested in trying to implement this. Seems like it is the main blocker for this PR |
foldexpr is already window local and there are no plans to change this. Note window local options can be local to a specific buffer in a specific window (via |
Ah okay, then I misunderstood @mjlbach's comment here:
@w4v3 are you still working on this PR? Or should someone else take over possibly? |
I'm happy to work on getting this merged (i.e. resolving conflicts, writing tests, and a bit of restructuring) but I also thought that the window-local nature of foldexpr would stand in the way of this PR. I suppose I'll finish it up and then see what the maintainers decide. |
As a reference, the plugin nvim-ufo implements support for this capability. |
a365287
to
a6d5852
Compare
77b6613
to
5581f6c
Compare
I'm once again ready for comments. I've implemented the following changes:
Since the implementation does not touch We could also issue the request inside |
I would highly advocate we do this and remove
This is not something the user should need to think about. |
One problem with this is that then every time the
In that case, under which circumstances would you say the cache should be updated? Currently I'm using this with an I'm starting to tend towards thinking that the |
Will resolve #12836. Ready for comments now.