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

JavaScript/TypeScript region folding with //region does not work #29379

Open
GiDW opened this issue Jan 10, 2019 · 7 comments
Open

JavaScript/TypeScript region folding with //region does not work #29379

GiDW opened this issue Jan 10, 2019 · 7 comments
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Domain: Outlining Relates to multi-line regions that editors can collapse Suggestion An idea for TypeScript

Comments

@GiDW
Copy link

GiDW commented Jan 10, 2019

  • VSCode Version: 1.30.2
  • OS Version: Linux x64 4.20.0-arch1-1-ARCH

Steps to Reproduce:

  1. Use //region and //endregion in JavaScript and/or TypeScript files to create folding regions.

Does this issue occur when all extensions are disabled?: Yes

The release notes for 1.17 mention that support was added for folding regions. For JavaScript/TypeScript, both //#region //#endregion and //region //endregion were added. However only //#region //#endregion seem to work. //region //endregion do not work.
This is annoying because some projects I work on use this syntax throughout all the code.

vscode_folding_regions

Code snippet

//region region
//endregion

// region region with space
// endregion

//#region #region
//#endregion

// #region #region with space
// #endregion
@vscodebot
Copy link

vscodebot bot commented Jan 10, 2019

@saranshkataria
Copy link

Verified that it is not working. I can take a shot at fixing this.

@mjbvz mjbvz self-assigned this Jan 10, 2019
@mjbvz mjbvz transferred this issue from microsoft/vscode Jan 11, 2019
@mjbvz mjbvz removed their assignment Jan 11, 2019
@mjbvz
Copy link
Contributor

mjbvz commented Jan 11, 2019

Moved upstream to TypeScript for more feedback since we now use language aware folding. We should wait for more feedback to see if //region is used enough vs to //#region to warrant support

@DanielRosenwasser DanielRosenwasser added Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript Domain: Outlining Relates to multi-line regions that editors can collapse labels Jan 11, 2019
@Popeye4242
Copy link

Popeye4242 commented Jan 4, 2021

@mjbvz I just want to mention that in WebStorm // region is supported by default and // #region might be supported too as you can define custom region expressions there.
I think VS Code should allow that too. That way region expression from other editors can be supported too without additional work.

@ilius33
Copy link

ilius33 commented Mar 23, 2021

Isn't it done already?
https://code.visualstudio.com/updates/v1_17#_folding-regions

@Sti2nd Sti2nd mentioned this issue Nov 21, 2021
@pixelpax
Copy link

pixelpax commented Mar 3, 2023

@ilius33 nope. The docs say so, but it's broken.

It's a frustrating issue, because it means that custom code folding is not possible in teams that works with multiple IDEs, nor in open source projects.

@yougotwill
Copy link

For anyone looking for a solution to this.

  1. Install https://marketplace.visualstudio.com/items?itemName=maptz.regionfolder
  2. Copy this into your settings.json
// Comment region folding
"maptz.regionfolder": {
		"[javascript]": {
		  "foldStart": "// region [NAME]",
		  "foldStartRegex": "^[\\s]*//[\\s]*[#]*region[\\s]*(.*)[\\s]*",
		  "foldEnd": "// endregion",
		  "foldEndRegex": "^[\\s]*//[\\s]*[#]*endregion",
		  "foldDefinitions": [
		    {
		      "foldStart": "/* region [NAME] */",
		      "foldStartRegex": "^[\\s]*/\\*[\\s]*[#]*region[\\s]*(.*)[\\s]*\\*/[\\s]*$",
		      "foldEnd": "/* endregion */",
		      "foldEndRegex": "/\\*[\\s]*[#]*endregion"
		    }
		  ]
		},
		"[javascriptreact]": {
		  "foldStart": "// region [NAME]",
		  "foldStartRegex": "^[\\s]*//[\\s]*[#]*region[\\s]*(.*)[\\s]*",
		  "foldEnd": "// endregion",
		  "foldEndRegex": "^[\\s]*//[\\s]*[#]*endregion",
		  "foldDefinitions": [
		    {
		      "foldStart": "/* region [NAME] */",
		      "foldStartRegex": "^[\\s]*/\\*[\\s]*[#]*region[\\s]*(.*)[\\s]*\\*/[\\s]*$",
		      "foldEnd": "/* endregion */",
		      "foldEndRegex": "/\\*[\\s]*[#]*endregion"
		    }
		  ]
		},
		"[typescript]": {
		  "foldStart": "// region [NAME]",
		  "foldStartRegex": "^[\\s]*//[\\s]*[#]*region[\\s]*(.*)[\\s]*",
		  "foldEnd": "// endregion",
		  "foldEndRegex": "^[\\s]*//[\\s]*[#]*endregion",
		  "foldDefinitions": [
		    {
		      "foldStart": "/* region [NAME] */",
		      "foldStartRegex": "^[\\s]*/\\*[\\s]*[#]*region[\\s]*(.*)[\\s]*\\*/[\\s]*$",
		      "foldEnd": "/* endregion */",
		      "foldEndRegex": "/\\*[\\s]*[#]*endregion"
		    }
		  ]
		},
		"[typescriptreact]": {
		  "foldStart": "// region [NAME]",
		  "foldStartRegex": "^[\\s]*//[\\s]*[#]*region[\\s]*(.*)[\\s]*",
		  "foldEnd": "// endregion",
		  "foldEndRegex": "^[\\s]*//[\\s]*[#]*endregion",
		  "foldDefinitions": [
		    {
		      "foldStart": "/* region [NAME] */",
		      "foldStartRegex": "^[\\s]*/\\*[\\s]*[#]*region[\\s]*(.*)[\\s]*\\*/[\\s]*$",
		      "foldEnd": "/* endregion */",
		      "foldEndRegex": "/\\*[\\s]*[#]*endregion"
		    }
		  ]
		}
},

This adds support for //region, // region, // #region, /* region */, /*region */, /* #region */ comments in JavaScript, TypeScript and React files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Domain: Outlining Relates to multi-line regions that editors can collapse Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

8 participants