Show HN: Making #regions actually useful in VSCode

9 alyt 2 5/16/2025, 1:39:44 PM github.com ↗
Hey HN,

For anyone unfamiliar: you can use `#region My Region` and `#endregion` comments to organize your code into foldable "regions".

Before building this extension, I'd use regions as a last resort, e.g. for large test files or classes that aren't worth splitting up more, or code that can't be split at all. They'd help somewhat, but the lack of tooling made them pretty underwhelming to work with. So I built out Region Helper, which as of yesterday's release provides:

- Commands / hotkeys for jumping between / selecting regions

- Fuzzy search (like "Go to Symbol" but for regions)

- A "Regions" tree view (interactive: click to navigate, and auto-highlights cursor's active region)

- A "Full Outline" tree view: like the builtin Outline, but incorporates regions (also interactive)

- Diagnostics: blue squiggle warnings when you have unmatched #region / #endregion markers

- Builtin support for 49 languages, customizable via settings

- An API for accessing Region Helper's data, so devs can build their own region extensions without needing to re-parse regions

- (New) Expand/Collapse All tree actions and persisted tree item collapse state across sessions

It's also performant even on massive files, e.g. TypeScript's ~50K LOC `checker.ts`.

These days, I personally enjoy using regions way more, and also add them more often to my code, now that they also serve as quick-jump points while navigating a file. Still definitely important not to overuse them, but I don't find them to be nearly as much of a code smell as I might have before.

If you're extra curious, you can check out Region Helper's source code to see a few real examples of where I've used them while building out this extension.

P.S. if you didn't know, your VSCode settings files (e.g. `settings.json`) are JSONC and support `// #region` and `// #endregion` markers. Since they can't be split into multiple files, regions are a pretty convenient way to organize them.

Feel free to share your own thoughts on regions and whether or not you find them useful ever, always curious to hear others' opinions.

Comments (2)

badmonster · 42m ago
Is there any plan to support nested region collapsing/expanding directly from the editor, similar to how VSCode handles folding for functions or classes?
alyt · 7h ago
Btw, another extension I'd personally recommend is Region Highlighter by 'Wiensss', which makes regions easier to see in the editor itself by coloring them, and also provides a command for making regions (although it is limited in language support). I don't currently use any other region extensions.

Region Highlighter: https://marketplace.visualstudio.com/items?itemName=Wiensss....