Skip to content

About

VS Code extension that shows inline cyclomatic complexity via CodeLens with a sortable sidebar report and JSON/CSV export for JavaScript, TypeScript, Python, Java, and C#. Short version (if you want compact): Inline cyclomatic complexity CodeLens + report panel for JS/TS/Python/Java/C# in VS Code.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Repository files navigation

Complexity Lens

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.

What It Does

  • 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#

How Complexity Is Calculated

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)
  • switch cases
  • catch clauses
  • ternary expressions
  • short-circuit logical branches (&&, ||, and language-specific null-coalescing where applicable)

Severity Mapping

By default:

  • <= 5 -> low
  • 6..19 -> medium
  • >= 20 -> critical

Thresholds are configurable in settings.

Architecture Overview

Main runtime components:

  1. src/extension.ts
  • activation entrypoint
  • command registration
  • event-driven analysis pipeline
  • in-memory cache and refresh orchestration
  1. src/analyzers/*
  • language-specific complexity analyzers
  • JavaScript: Babel parser
  • TypeScript: TypeScript Compiler API
  • Python/Java/C#: tree-sitter
  1. src/providers/CodeLensProvider.ts
  • renders inline complexity lenses
  • applies filtering and label formatting
  1. src/providers/SidebarProvider.ts
  • renders Explorer panel tree
  • groups by file, sorts by complexity
  • shows parse-warning section for failed files
  1. src/utils/*
  • config.ts: defaults + threshold validation + safe merge
  • debounce.ts: document-change throttling
  • exporter.ts: JSON/CSV report generation
  • performance.ts: p95 metrics + large-file skip policy

Runtime Workflow

  1. File is opened/edited/saved
  2. Extension receives VS Code document events
  3. Analysis is run (debounced on edit)
  4. Per-document results are cached
  5. CodeLens provider renders inline scores
  6. Sidebar provider refreshes report entries

If file size is over threshold (> 5000 lines), analysis is skipped and a warning lens is shown.

Commands

  • 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

Configuration

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

Installation

From VSIX (local/manual)

  1. Build package:
npm run package:vsix
  1. In VS Code:
  • Command Palette -> Extensions: Install from VSIX...
  • Select complexity-lens-0.1.0.vsix

CLI install

code --install-extension complexity-lens-0.1.0.vsix --force

Usage

  1. Open a supported source file with function/method definitions
  2. Run Refresh Complexity Lens
  3. Observe inline ↻ Complexity: X annotations
  4. Open Explorer -> Complexity Report
  5. Click entries to navigate to hotspots
  6. Export report when needed

Development and Validation

npm install
npm run build
npm run test:unit
npm run test:integration
npm run package:vsix
npm run check

Testing Strategy

  • 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

CI Pipeline

GitHub Actions workflow: .github/workflows/ci.yml

Jobs:

  • unit tests
  • integration tests
  • VSIX package build

Known Operational Notes

  • 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

License

MIT

About

VS Code extension that shows inline cyclomatic complexity via CodeLens with a sortable sidebar report and JSON/CSV export for JavaScript, TypeScript, Python, Java, and C#. Short version (if you want compact): Inline cyclomatic complexity CodeLens + report panel for JS/TS/Python/Java/C# in VS Code.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages