by alyt on 3/26/25, 12:45 PM with 0 comments
Quick primer for anyone unfamiliar: you can insert `#region My Region` and `#endregion` comment markers in your code to organize it. Editors like VSCode will make these "regions" foldable, show them in the minimap, etc. Regions can be nested.
While modular code and clean file/folder structure are usually enough, I find regions can be super helpful in certain contexts, like large test files, long classes, or even VSCode's `settings.json` (which is JSONC under the hood and allows `// #region` comments).
Some great tools already exist (e.g. I recommend Region Highlighter), but I always wished there were certain ones: fuzzy search, keyboard navigation, a tree view that tracks the cursor's region*, regions merged into the Outline**, etc. So I built them, plus a few extras like unmatched boundary warnings and a small API to help other devs build on top of this, along with builtin support for ~50 languages (customizable/extendable via settings).
This was a fun side project that's made it easier and more enjoyable to work with regions, when I do. What surprised me though, is that it's also changed when I use them in the first place. I'm now adding regions where I previously wouldn't have bothered, like an API constants region with a subregion for each endpoint. Not because the file is especially long or needs the extra structure, but because it can benefit from the added visual hierarchy and quick navigation points that regions now provide. Still important not to overuse them of course, but having the option is nice.
Hope it's useful to some of you too!
Also while we're here, I'd be curious to hear your general thoughts on regions. Do you hate them (I know some people do, which is valid)? If you use them, when do you find them most useful? Etc.
---
* A non-tracking tree view extension existed, which I considered submitting a PR for; but its repo was inactive.
** VSCode's API didn't support adding regions to the builtin Outline, except as a separate regions-only section. This was a brutal rabbithole actually; I tried multiple methods that all eventually had issues. Ultimately, the best path was for Region Helper to provide its own separate "Full Outline" view.