Skip to content
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] Collapse ending brace to the same line #3352

Open
Tyriar opened this issue Feb 23, 2016 · 91 comments
Open

[folding] Collapse ending brace to the same line #3352

Tyriar opened this issue Feb 23, 2016 · 91 comments
Assignees
Labels
editor-folding Editor code folding issues feature-request Request for new features or functionality
Milestone

Comments

@Tyriar
Copy link
Member

Tyriar commented Feb 23, 2016

Consider a large JavaScript file

function a() {
  ...
}

function b() {
  ...
}

function c() {
  ...
}

and so on...

Collapsing all currently yields:

function a() { ...
}

function b() { ...
}

function c() { ...
}

and so on...

This would be more readable if the closing brace was on the same line:

function a() { ... }

function b() { ... }

function c() { ... }

and so on...

Here is how other prominent editors handle the above:

Atom

image

Brackets

image

Sublime Text 3

image


VS Code

image

@tht13
Copy link
Contributor

tht13 commented Feb 24, 2016

This would not work for languages which do not use punctuation to signify code blocks (i.e python)

Code Folding at the moment uses indentation and so will close everything up to the next line on the same indentation level as the folding line. The implementation would have to change to fold the closing bracket as this would cause issues in some languages

@joaomoreno
Copy link
Member

👍

@joaomoreno
Copy link
Member

ping @alexandrudima

@aeschli aeschli added the editor label Feb 24, 2016
@aeschli aeschli added this to the Backlog milestone Feb 24, 2016
@aeschli aeschli added feature-request Request for new features or functionality editor-folding Editor code folding issues labels Feb 24, 2016
@aeschli aeschli changed the title Proposal: Code folding collapses ending brace to the same line [folding] Collapse ending brace to the same line Feb 24, 2016
@pom421
Copy link

pom421 commented Jul 12, 2016

👍
I like the Atom's way. We save a line and the ending curly brace is not virtually on the same line than the beginning one (unlike Bracket).

@danjoa
Copy link

danjoa commented Dec 23, 2016

👍 definitely, would help so much

@g5codyswartz
Copy link

g5codyswartz commented Feb 1, 2017

I like how Jetbrains does theirs which matches "bracket"
image

I also love being able to fold not only from the first bracket but also the last bracket.

They also have essentially peeking for brackets when they're not on screen so you can see what they belong to. I used to comment what ending brackets belonged to, then I stopped due to the IDE, now I'm feeling lost again w/o it.
image

I also really like how notepad++ puts the trailing line as mentioned in Alternative Designs #2

@Spown
Copy link

Spown commented Aug 28, 2017

I'm for the current model, but since people still think there is something to be corrected I think a preference is in order, something like editor.foldingConsumeLastLine: bool

@renestalder
Copy link

Also would prefer a way to make it one-line. I often use the folding in CSS and liked the way the Jetbrains IDEs put the collapsed selectors on one line.

@gabrielmaximo
Copy link

Can you solve it? I have this same problem uncomfortable, I read the other post about it, but I did not see anything finished that can help me, someone there knows how to solve ?? it really is very uncomfortable working with multiple collapsed lines, because with this line more than "}" it is difficult and confusing to work.

@manyfew
Copy link

manyfew commented Mar 7, 2018

I like the 'Brackets' example, looks clean

@jeasonstudio
Copy link

jeasonstudio commented Apr 2, 2018

image

It is a good choice to show the number of folded code lines like vim, and make the folded code more visible.

@faustinoaq
Copy link
Contributor

Hi people!

I think would be nice to see vscode folding with info about amount of lines folded like Netbeans:

screenshot_20170620_215124

BTW: Thank you for this awesome code editor! 😄

Related issue here: #29155

@ArthaTi
Copy link

ArthaTi commented May 12, 2018

I would really like to see this implemented. But, in the meantime, is there an extension that does that?

@garpunkal
Copy link

I would to see this implemented soon. It's a right pain. Visual Studio working perfectly for collapse and expanding structure.

@Detnator-Neo
Copy link

Detnator-Neo commented Feb 27, 2022

@stevemcmillen: Code folding can be based on one of two things: (1) indentation (2) language specific rules. It is set in the settings with editor.foldingStrategy, to either "indentation" or "auto" (auto = language specific rules).

Or in the settings UI:
Screen Shot 2022-02-27 at 3 36 18 PM

That, arguably makes this issue a little more complicated than you're suggesting, however I still agree that it should be a higher priority than it seems to be.

Every decent IDE does this. I for one don't understand why it's apparently so difficult and not a priority for VSCode -- well other than the fact that the VSCode devs are devs like us, and as with any dev project, we juggle priorities based on many factors, including demand, ease/difficulty of implementation, and others.

Presumably if this thread grows and more people are +1-ing it, then that's increased "demand" and will hopefully push it up.

@Detnator-Neo
Copy link

Detnator-Neo commented Feb 27, 2022

After my comment above, I feel a need to add the following:

There's a number of requests here, and maybe this should be broken out into a few separate "issues"...?
Recap:

  1. Option to consume last line of code block when folding (the original issue, but make it optional)
  2. When code block is folded, show number of consumed/hidden/folded lines (here and here)
  3. Ability to fold from the bottom as well as from the top (here)
  4. When unfolded code has opening bracket (or other code block symbol) on line after function (or whatever) name, then option to move that opening bracket to same line as function name when folding up. (here and here)
  5. Ability to fold code within a single line (here and here)

I think that's everything. If anyone thinks I missed anything please feel free to let me know.

To the VSCode devs (@joaomoreno ?, @aeschli ?): The explicit-folding extension gets some of this right -- without having access to internal code. You guys did a pretty good job with bracket pair colorization, improving on and acknowledging CoenraadS's work. Is there anything significant stopping you from doing the same with daiyam's?**.

And it's not like you have to do it all at once. Is there anything stopping you at least implementing natively what daiyam has done, and then adding to it bit by bit over time from there?

I understand your point about it being up to the language extension providers, so ok... what about the language extensions provided with VSCode/by Microsoft (JS, TS, C++, to name a few)? Please correct me if I've misunderstood the connection between VSCode and those extensions. If not you guys, who do we talk to about those particular languages?

( ** @daiyam I seem to recall you stating you'd be happy for them to do that, but can't find where I saw that. Please correct me if I'm wrong).

@angelozerr
Copy link
Contributor

In our XML Language Server we decide to support this issue, but it provides this bug redhat-developer/vscode-xml#690 (comment)

In other words, if you have this XML:

<note>
	<foo>

		bla bla bla

	</foo>
</note>

and you fold the root note , and you select (without Ctrl+A) the <note> and you type space, it doesn't remove the whole content and teh XML becomes an invalid XML:

	<foo>

		bla bla bla

	</foo>
</note>

In Eclipse IDE, it solves the problem by opening the fold, when you try to update it.

  • Here a demo with vscode:

FoldingWithVScode

  • Here a demo with Eclipse IDE:

FoldingWithEclipseIDE

@daiyam
Copy link
Contributor

daiyam commented Apr 1, 2022

@angelozerr I think your issue is different from the original issue. You should open a new one.

@angelozerr
Copy link
Contributor

@angelozerr I think your issue is different from the original issue. You should open a new one.

I would like to highlight a problem with the "Collapse ending brace to the same line" issue but if you think it's better to create a new issue, I can do that.

@n-gist
Copy link
Contributor

n-gist commented Sep 4, 2022

Explicit Folding extension does the trick.

But while I was reading this thread.

As @aeschli mentioned:

Since a while we allow extensions to contribute folding range providers. If none is present we fall back to indentation based folding ranges.

I checked it in .js file for this piece of code (} is aligned to return for this test)

if (folding) {
    return;
    }

And it turned out that it folds differently based on editor.foldingStrategy. It folds to

if (folding) { ...
    }

For auto, and to

if (folding) { ...

For indentation

This could mean that, unlike in the past, now indentation-based stategy is not the only one VS Code has, and there is already some bracket-based or language-specific strategies under the hood, or indentation-based add-ons that weren't thought of as a possibility before. In any case, it looks like there is now room for the code that can solve the issue.

@jonlepage
Copy link

r

not work at all for me

@mtbaqer
Copy link
Contributor

mtbaqer commented Jan 23, 2023

Hey everyone, I managed to make an extension that solves this problem along with other many requested folding-related issues. You can find it here:

https://marketplace.visualstudio.com/items?itemName=MohammadBaqer.better-folding

A demo of the extension in action:

Screen.Recording.2023-01-23.at.11.29.10.mov

@jonlepage
Copy link

Hey everyone, I managed to make an extension that solves this problem along with other many requested folding-related issues. You can find it here:

https://marketplace.visualstudio.com/items?itemName=MohammadBaqer.better-folding

A demo of the extension in action:

Screen.Recording.2023-01-23.at.11.29.10.mov

My Hero !!

@AlekseyPolishchuk
Copy link

Hey everyone, I managed to make an extension that solves this problem along with other many requested folding-related issues. You can find it here:

https://marketplace.visualstudio.com/items?itemName=MohammadBaqer.better-folding

A demo of the extension in action:

Screen.Recording.2023-01-23.at.11.29.10.mov

Cool stuff! But I have one problem, folding stops working in html

@mtbaqer
Copy link
Contributor

mtbaqer commented Jan 23, 2023

Hey everyone, I managed to make an extension that solves this problem along with other many requested folding-related issues. You can find it here:
https://marketplace.visualstudio.com/items?itemName=MohammadBaqer.better-folding
A demo of the extension in action:
Screen.Recording.2023-01-23.at.11.29.10.mov

Cool stuff! But I have one problem, folding stops working in html

HTML, JSX and TSX support coming soon. You can see the full list here

@AlekseyPolishchuk
Copy link

HTML, JSX and TSX support coming soon. You can see the full list here

This is great! Thanks a lot. I'm looking forward to it.

@tresabhi
Copy link

tresabhi commented Jan 24, 2023

@mtbaqer that's amazing! Could you also publish this on Open VSX?

@Cyberavater
Copy link

Hey everyone, I managed to make an extension that solves this problem along with other many requested folding-related issues. You can find it here:

https://marketplace.visualstudio.com/items?itemName=MohammadBaqer.better-folding

A demo of the extension in action:

Screen.Recording.2023-01-23.at.11.29.10.mov

Thanks man, I was waiting for it for a long time.

@niczoom
Copy link

niczoom commented Feb 26, 2023

Thanks for your hard work, the folding extension is fantastic!

@realfresh
Copy link

Hey everyone, I managed to make an extension that solves this problem along with other many requested folding-related issues. You can find it here:

https://marketplace.visualstudio.com/items?itemName=MohammadBaqer.better-folding

A demo of the extension in action:

Screen.Recording.2023-01-23.at.11.29.10.mov

Mate, you are a bloody legend!

@Mr-D-Anderson
Copy link

image
It still shows the closing bracket for me. Didn't change any settings.

@ScottBeeson
Copy link

@mtbaqer 's extension "Better Folding" works great! Until you restart vscode. Then it reverts to the default behavior.

Immediately after installation:
image

After restarting vscode:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
editor-folding Editor code folding issues feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests