-
Notifications
You must be signed in to change notification settings - Fork 30.7k
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
[folding] API for programmatically folding lines #37682
Comments
No, we don't have any API that lets you fold away lines. |
I have a nice extension in mind which I can't implement without this API. I often "divide" my files/functions with some comments: function foo () {
/* A DIVIDER */
const foo = 123;
const bar = 321;
/* ANOTHER DIVIDER */
asd ();
asd ();
/* WRAPPING UP */
qwerty ();
return 123;
} And I'd like to have an extension that allows me to fold all the lines between 2 consecutive equally-indented dividers, but I can't implement it without this API. VSC already supports I'd submit a PR for this, but I guess it wouldn't be easy to implement this for someone unfamiliar with the codebase. In case it's actually quite doable, and you'd also like this API please do let me know 👍 |
We have API the folding range provider API that lets extensions define folding regions. We also have public fold/unfold commands that extensions can use. |
For my personal use cases that's not necessary.
If I'm understanding this correctly that would allow us to define custom folding regions, is that correct? That'd be completely useless for my use cases for 2 reasons:
|
You are right, UI-wise we don't support what you show in your mock-up: We currently represent folded lines by showing the content of the first line, followed by I think number 2 you can already do with the current API. You do it by defining a folding range provider that creates folding ranges from the end of the separator to the beginning of the next one. Ok to close this issue? We already have API to defined folded regions, but I understand there are other features you also need for your use case, but we have also issues for these. |
The perhaps wrong assumption here is that folding regions have to contain more than 1 line. I don't feel like being able to customize the text displayed would be that useful, just displaying "
I wasn't aware of the existing APIs related to folding regions, it looks like my hypothetical extension could be implemented with those indeed. I don't necessarily want those folding regions to go from divider to divider though, as the behavior should be indentation-aware and there might not be an ending divider.
I don't think the other issues you linked to really cover this and I'd prefer if this remained open, but if you think otherwise feel free to do as you please. The main issue I see is that while there are some APIs for defining folding regions they are not dynamic enough for allowing me to implement the use case I'm showcasing in the original post. If you try PlainTasks in Sublime you can see that a user can fold all tasks containing a specific tag, that's unimplementable with the current APIs, as a task might have multiple tags just to mention one issue so what would happen when clicking the folding chevron in the gutter? There really shouldn't be any chevron for this (at least for folding, for unfolding it would be unambiguous I think). What's really needed is an API for programmatically folding lines, which I don't think it's tracked anywhere else, right? |
#70794 speaks about defining the full content of the first line. In your case you would just want
That's really up to your folding range provider to decide. You have the full freedom do define from where the folding range goes. The restrictions are that we can only fold full lines and the way how we render the first line (the line that contains the folding action and marker). Looking at PlainTasks, I think that can all be implemented with the current APIs and commands.
You would implement a command that e.g. asks the user for a tag or uses the tag at the cursor position. Then you evaluate which ranges have that tag and then you execute the command |
I wasn't aware of the
IMHO point 1 shouldn't be required, I should just be able to tell the editor which lines to fold/unfold and that should be it, at least for this specific use case. |
The folding range provider API is equivalent to an API that let's you set folding ranges. Instead of you telling, we ask you. |
If step 1 is not actually required then I'd consider this implemented already 👍 I'll play with |
Cool. I close the issue as we have the APIs, and we have issues for the gaps as discussed. |
I've got a request for a feature for one of my extensions that can't be implemented without APIs for programmatically folding lines.
In Sublime one can go from this:
To this:
Basically folding arbitrary lines. I'm not aware of any existent API that can be used for this.
Can this be implemented?
The text was updated successfully, but these errors were encountered: