Is your feature request related to a problem? Please describe. Vscode can fold the code with region comments if supported by the language:

https://code.visualstudio.com/docs/editing/codebasics#_folding

It would be great to have this feature in golang too to be able to collapse whole regions in the code

Describe the solution you'd like A solution where region comments like // #region for example are supported. If this needs to be defined in golang itself, I can raise a feature request there too

Describe alternatives you've considered there are none

Additional context https://code.visualstudio.com/docs/editing/codebasics#_folding

Comment From: h9jiang

Is this something you are looking for? The comment inside of the issue suggest there is an extension available, I have never used regional folding, please let me know if this is good enough for you.

https://github.com/golang/go/issues/67398

Comment From: firefart

Thanks for the link. After reading through this issue, does this need to implemented in gopls so it would support folding of regions? Ideally this would work outside the box without any plugins or configs

Comment From: h9jiang

Hi,

If this want to be supported in go, it should be implemented in the gopls side because gopls is the folding range provider.

However, I see discussion happened before, the feature you are asking is not only for go, so maybe a general purposed folding provider should do the work for you. It does not necessary for gopls to implement it. Based on https://github.com/golang/vscode-go/issues/134, vscode will try to merge folding ranges reported by different extensions. Basically, folding ranges report by extension A and extension B can be co-exist.

I guess that is the reason why go have not implement the region folding. I tried the extension mentioned by Alan (the better folding extension) but it sometimes does not work.

I will transfer this issue to gopls and see if there is a change of opinion. It does feel weird to see Go missing from the table.

cc @adonovan @findleyr

Comment From: h9jiang

Also, as Hana suggested previously in issue

You can explicitly enable the vscode folding provider by adding,

"editor.foldingStrategy": "indentation",

Once this is enabled, the region folding will show up that offered by vscode.

Image

But this also means the folding ranges reported by the gopls are thrown away.