zed-industries / zed

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
https://zed.dev
Other
50.92k stars 3.15k forks source link

One-lined fold #4455

Open rosingrind opened 1 year ago

rosingrind commented 1 year ago

Check for existing issues

Describe the feature

Pardon my toxic rant, idk why but I'm overflown with hatred when I click "fold" and see the {... on one line and dangling } on the other line. Zed is definitely a fresh breath and looks very promising, but I'm very frustrated when these kinds of projects do pick up bad habits from the very beginning.

I don't know who started this ugliness parade, but as far as I remember, vscode brought this up to masses. Now they have at least 3 big and easy to find issues for "same line folding", and an entire plugin for this. I know this may be too opinionated here, but I'm definitely not alone.

Imagine a situation: you use a formatter like rustfmt on your code with empty code blocks:

fn foo() {
    let something = 123;
    if something == 2 {} // TODO
    todo!()
}

fn bar() {             }

fn main() {

}

And you get this:

fn foo() {
    let something = 123;
    if something == 2 {
    } // TODO
    todo!()
}

fn bar() {
}

fn main() {
}

Every formatter either do fn main() {} by default, or add an option to leave closing bracket on second line for older code formatting conventions. Again, I may be biased but I believe that leaving closing pair on second line is not fine and looks annoying.

Just fold to 1 (one) line, not 2 (two). Is it so hard to do?

More than that, you already can do this, look up an attached screenshot from your own project:

If applicable, add mockups / screenshots to help present your vision of the feature

image
bencemeszaros commented 10 months ago

Absolutely, one hundred percent, fully and totally agree with @rosingrind. Upvote, thumbs up and whatever is needed to draw more attention to this issue. To anyone looking for a code editor that can fold to a single line, well tough luck. Brackets, Atom are both discontinued, VSCode can only do this using a (quite buggy) third party plugin, and JetBrains Fleet preview is quite picky when it comes to folding (cannot fold multiline comments in any way, cannot fold function arguments, but can fold function body to a single line).

I understand that this is a complex issue (eg. folding Python vs folding JavaScript are quite different, folding if-elseif-else is tricky and so on) but it is also an essential tool when working on massive files with a ton of definitions. This is why I tested this code editor in the first place, to finally have an editor that can properly fold.

If there is anything I can help to implement this feature (testing, debugging, documenting, anything) I am happy to help, just please make a code editor that can fold properly.

7flash commented 10 months ago

Folding is not working as expected as it does in other editors.

Consider this example when I press on line 297

image

It only folds a small piece of code when expected to fold full body of function

image
thelegendtubaguy commented 7 months ago

Remembering folds per file would be amazing

ndecamino commented 2 weeks ago

Checking to see if there is any updates on this? I would very much appreciate this feature!