C++ Ranges Helper
C++ Ranges Helper is a VS Code extension for people who are already using modern C++ and want better feedback while writing ranges, views, and related algorithms.
It is built around AST-based analysis rather than regex heuristics. The extension can inspect a pipeline, explain what each stage does, estimate stage-by-stage complexity, surface compatibility issues, and offer rewrite suggestions for a small set of common pre-ranges patterns.
What It Does
C++ Ranges Helper currently focuses on four areas:
- Hover documentation for
std::views::* and std::ranges::*
- Pipeline analysis for chained ranges expressions
- Rewrite suggestions for selected loops and algorithm patterns
- Lightweight diagnostics for concept requirements, C++ version mismatches, and a few performance smells
Feature Overview
Pipeline analysis
When you hover a pipeline, the extension can show:
- The inferred input and output type of the chain
- A per-stage breakdown of the pipeline
- Stage-by-stage complexity notes
- Basic data-flow previews
- Concrete output previews when the input is statically known, for example
constexpr arrays
Examples of pipelines it can reason about include:
filter -> transform -> take -> reverse
keys, values, join, stride, chunk, adjacent, cartesian_product
- Some constant-input filters such as equality, modulo checks, and simple numeric comparisons
Hover documentation
For supported views and algorithms, hover text includes:
- Category and header
- C++ version
- Time and space complexity
- Requirements
- A short explanation of the adapter or algorithm
- A cppreference link
Rewrite suggestions
The extension can offer rewrite hints and Quick Fix actions for a focused set of patterns.
Supported today:
- Range-based
for loop with an inner if
- Suggested rewrite:
views::filter
std::transform(begin, end, out, func)
- Suggested rewrite:
views::transform
- Selected nested range-based loops
- Suggested rewrite:
views::join or views::cartesian_product
- Member-access lambdas in selected classic algorithms
- Suggested rewrite: use
std::ranges::* with projections
- Member-access lambdas in selected
std::ranges::* calls
- Suggested rewrite: replace the lambda with a projection such as
&Type::member
Projection suggestions are intentionally conservative. They appear only when the lambda clearly projects a single member and the rewrite is mechanically safe.
Diagnostics
The extension can surface:
- Concept requirement violations
- C++ version mismatches for views and algorithms
- A small set of performance hints
- Rewrite availability hints
Example Rewrite Coverage
A few examples the extension is designed to recognize:
for (const auto& item : products) {
if (item.available) {
use(item);
}
}
Suggested direction:
for (const auto& item : products | std::views::filter([](https://github.com/mberk-yilmaz/cpp-ranges-helper/blob/HEAD/const auto& value) { return value.available; })) {
use(item);
}
std::transform(values.begin(), values.end(), std::back_inserter(output), square);
Suggested direction:
std::ranges::copy(values | std::views::transform(square), std::back_inserter(output));
std::sort(records.begin(), records.end(), [](https://github.com/mberk-yilmaz/cpp-ranges-helper/blob/HEAD/const Record& left, const Record& right) {
return left.score < right.score;
});
Suggested direction:
std::ranges::sort(records, {}, &Record::score);
Settings
The extension currently uses the cppranges.* configuration namespace for backward compatibility.
Important settings:
cppranges.enabled
cppranges.cppVersion
cppranges.hover.enabled
cppranges.inlayHints.enabled
cppranges.inlayHints.dataFlowPreview
cppranges.inlayHints.rewriteOverlay
cppranges.refactoring.enabled
cppranges.codeLens.rewriteHints
cppranges.cache.maxSize
cppranges.debug
Development
Build
npm install
npm run compile
npm run package
Run in VS Code
Open the workspace in VS Code and launch the extension development host from the debugger.
Tests and fixtures
The repository includes TypeScript tests and several C++ fixture files under src/test/fixtures/ that are useful for manual validation.
Packaging and Publishing
To produce a VSIX locally:
npm run package
Before publishing to GitHub or the VS Code Marketplace, verify the following:
package.json has the final publisher
- The repository URL is added to
package.json
LICENSE is present
- The Marketplace icon is added, if you want one
- The README reflects the real supported rewrite patterns and limitations
- The generated VSIX is built from a clean working tree
Current limitations
This extension is intentionally narrow and conservative.
- Not every loop can be rewritten safely
- Projection suggestions are limited to simple single-member lambda patterns
- Type inference is useful, but not complete for every C++ construct
- Some cppreference links require explicit overrides because cppreference URL patterns are not perfectly uniform
Why this extension exists
C++ ranges are expressive, but the ergonomics in editors are still uneven. The goal here is not to auto-modernize everything. It is to give the user better visibility into what a pipeline means, where a rewrite is safe, and where a simpler ranges-based form already exists.