zokugun / vscode-explicit-folding

Customize your Folding for Visual Studio Code
MIT License
95 stars 14 forks source link

How to fold "if err != nil" #85

Closed diocletiann closed 1 year ago

diocletiann commented 1 year ago

I would like to start with folding exactly this entire block:

if err != nil {
   return err
}

If I use "end": "}" it catches other blocks but if I don't I can't get it to fold that last line. I guess end overrules while but I'm not sure how to have while look for more than one pattern. Thanks.

Config:


"explicitFolding.rules": {
        "go": [
            {
                "begin": "if err != nil",
                "whileRegex": "/return\serr/",
                "end": "}",
                "autoFold": true
            }
        ]
    }```
daiyam commented 1 year ago

Can you try:

"go": {
    "explicitFolding.rules": {
        "begin": "if err != nil",
        "whileRegex": "^\\s*(?:return\\serr|\\})",
        "autoFold": true,
    }
}
diocletiann commented 1 year ago

Thanks, I had the wrong escape syntax.

diocletiann commented 1 year ago

Your code works well and it also gave me a few other ideas. Is there a way to re-process the folding on demand? I would be nice to get back to baseline with a keybind.

Thanks for a great extension!

daiyam commented 1 year ago

The foldings are reprocessed when you have updated the file or have changed the config.