Skip to content
| Marketplace
Sign in
Visual Studio Code>Programming Languages>Universal RegionsNew to Visual Studio Code? Get it now.
Universal Regions

Universal Regions

AndyK

|
6 installs
| (0) | Free
Language-agnostic token-based regions with highlighting and folding.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Universal Regions

Universal Regions adds language-agnostic, token-delimited regions to every file type except extensions you explicitly exclude. A completed multiline region is shaded only when its exact start and end lines survive VS Code's folding-provider merge and range limit. Unclosed regions are shaded red from the opening token through the end of the file. Unmatched or mismatched end tokens get a red line highlight. Hover over an error highlight for an explanation. Error highlights do not require a folding range. Completed single-line regions and excluded files are not highlighted.

Configuration

Add settings such as these to your VS Code settings JSON:

{
  "universalRegions.startTokens": ["#region", "//<"],
  "universalRegions.endTokens": ["#endregion", "//>"],
  "universalRegions.excludeExtensions": ["lock", ".js"],
  "universalRegions.backgroundOpacity": 0.12
}

Each start token is paired with the end token at the same list index. Both lists should therefore have the same number of entries. Unpaired entries are ignored. Tokens must not contain whitespace. The label is the remaining text after the opening token on that line. A normal region's color is deterministic from that label, so adding or removing lines does not change its color. Regions with the same label share a color. Background opacity applies to both normal and error highlights.

Highlights stay visible while you type. Updates are debounced by 150 ms, retaining the existing background until its replacement is ready. Renaming a region changes its color after the update without clearing the background between characters. Editing one document does not interrupt highlights in other editors.

After changing Universal Regions settings, VS Code recomputes the folding ranges for open files automatically.

Pairing rules

Regions use a single stack. Opening tokens are pushed; an end token closes only the most recently opened region when it has the corresponding configured token pair. This means nested regions pair naturally. An end token that does not match the top open region is marked as an error and does not close any region. Open regions remain unclosed until valid matching end tokens are encountered.

VS Code's standard Fold command and gutter controls expose the collapsible regions. Universal Regions uses one language-agnostic provider with an all-file glob and wildcard fallback, alongside existing language providers. The glob removes the lower priority of a plain wildcard when a block comment and region start on the same line. VS Code breaks equal-priority ties by provider registration order, so an extension registering later can still win. Its public API does not expose an unconditional priority override. Ordinary language folds remain available.

Completed-region highlight checks respect disabled folding, indentation strategy, and the maximum region count. Error highlights remain visible even if folding is disabled or a folding provider fails. Highlights refresh after edits, editor changes, extension changes, and configuration changes. The public API does not expose the live gutter model or every provider refresh, so manually created folds and independent provider updates may differ until the next refresh.

Test in VS Code

  1. Open this extension folder in VS Code.
  2. Run npm install once, then press F5 and choose Run Universal Regions.
  3. VS Code opens an Extension Development Host with test-fixtures/regions.anything as its workspace. Open that file to verify normal, nested, and unclosed regions.

The launch configuration compiles the TypeScript first. It requires Node.js and npm to be installed and available on your PATH.

Run npm test to compile and run the parser and decoration lifecycle regression tests.

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
  • Your Privacy Choices
  • Consumer Health Privacy
© 2026 Microsoft