Complexity Lens is a VS Code extension that computes cyclomatic complexity and shows it directly in the editor as inline CodeLens annotations, plus a workspace-wide report panel in Explorer.
It is designed to make complexity hotspots visible during normal coding and review workflows, without requiring external dashboards.
- Shows complexity score above each function/method
- Uses severity-based signal (
low,medium,critical) - Provides a Complexity Report panel grouped by file
- Supports JSON/CSV report export
- Works across JavaScript, TypeScript, Python, Java, and C#
Complexity Lens follows cyclomatic complexity principles:
- Base score per function/method starts at
1 - Each decision point increments score by
+1
Decision points include constructs such as:
if/else if- loops (
for,foreach,while,do while) switchcasescatchclauses- ternary expressions
- short-circuit logical branches (
&&,||, and language-specific null-coalescing where applicable)
By default:
<= 5->low6..19->medium>= 20->critical
Thresholds are configurable in settings.
Main runtime components:
src/extension.ts
- activation entrypoint
- command registration
- event-driven analysis pipeline
- in-memory cache and refresh orchestration
src/analyzers/*
- language-specific complexity analyzers
- JavaScript: Babel parser
- TypeScript: TypeScript Compiler API
- Python/Java/C#: tree-sitter
src/providers/CodeLensProvider.ts
- renders inline complexity lenses
- applies filtering and label formatting
src/providers/SidebarProvider.ts
- renders Explorer panel tree
- groups by file, sorts by complexity
- shows parse-warning section for failed files
src/utils/*
config.ts: defaults + threshold validation + safe mergedebounce.ts: document-change throttlingexporter.ts: JSON/CSV report generationperformance.ts: p95 metrics + large-file skip policy
- File is opened/edited/saved
- Extension receives VS Code document events
- Analysis is run (debounced on edit)
- Per-document results are cached
- CodeLens provider renders inline scores
- Sidebar provider refreshes report entries
If file size is over threshold (> 5000 lines), analysis is skipped and a warning lens is shown.
Toggle Complexity Lens- Enables/disables annotations in current session
Refresh Complexity Lens- Re-runs analysis for open documents
Export Complexity Report- Saves current workspace report as JSON or CSV
Show Complexity Panel- Focuses the Explorer report view
Explain Complexity Score- Shows remediation guidance for selected function score
All settings are under complexityLens.*.
| Setting | Default | Description |
|---|---|---|
complexityLens.enabled |
true |
Master enable/disable switch |
complexityLens.thresholds.low |
5 |
Maximum score considered low |
complexityLens.thresholds.medium |
10 |
Default problematic boundary |
complexityLens.thresholds.high |
20 |
Minimum score considered critical |
complexityLens.showOnlyProblematic |
false |
Show only scores >= medium |
complexityLens.labelFormat |
↻ Complexity: {score} |
Supports {score} and {rating} |
complexityLens.languages |
language list | Language IDs to analyze |
complexityLens.excludePatterns |
[] |
Glob patterns to skip |
Validation rule:
low < medium <= high- invalid values fall back safely and emit a warning
- Build package:
npm run package:vsix- In VS Code:
- Command Palette ->
Extensions: Install from VSIX... - Select
complexity-lens-0.1.0.vsix
code --install-extension complexity-lens-0.1.0.vsix --force- Open a supported source file with function/method definitions
- Run
Refresh Complexity Lens - Observe inline
↻ Complexity: Xannotations - Open Explorer ->
Complexity Report - Click entries to navigate to hotspots
- Export report when needed
npm install
npm run build
npm run test:unit
npm run test:integration
npm run package:vsix
npm run check- Unit tests (
src/test/*)- analyzer correctness
- config semantics
- exporter format
- debounce/performance helpers
- Integration tests (
src/integration/*)- extension activation and command availability
- CodeLens rendering behavior
- toggle/refresh behavior
- export flow and panel behavior
GitHub Actions workflow: .github/workflows/ci.yml
Jobs:
- unit tests
- integration tests
- VSIX package build
- Very large files are intentionally skipped for responsiveness.
- Tree-sitter analyzers are lazy-loaded to reduce activation risk.
- If commands are missing in Command Palette, check:
- extension target (local vs WSL/container/SSH)
- extension activation state in
Developer: Show Running Extensions - output/devtools logs for activation errors
MIT