Skip to content
| Marketplace
Sign in
Visual Studio>Tools>CodeAnalysis Cognitive Complexity
CodeAnalysis Cognitive Complexity

CodeAnalysis Cognitive Complexity

Klaus Jaufer

|
20 installs
| (0) | Free
Calculates and displays Cognitive Complexity metrics for C# methods in CodeLens. Features configurable thresholds, performance optimizations, and support for Visual Studio 2022-2026.
Download

CodeAnalysis Cognitive Complexity VSIX

A Visual Studio extension that calculates and displays Cognitive Complexity metrics for C# methods using CodeLens technology.

Cognitive Complexity in action

Features

🎯 Cognitive Complexity Analysis

  • Real-time calculation of cognitive complexity for C# methods
  • CodeLens integration shows complexity scores directly in the editor
  • Visual indicators for complexity levels (good/warning/error states)
  • Detailed breakdowns of complexity contributors

⚙️ Configurable Options

  • Customizable threshold (default: 12) - Set your own complexity warning level
  • Logging control - Enable/disable detailed logging for debugging
  • Performance tuning - Adjustable polling interval for change detection

🚀 Performance Optimized

  • Batch processing for efficient change detection
  • Smart polling with configurable intervals
  • Memory efficient with proper resource cleanup
  • Low CPU usage with optimized algorithms

🔧 Visual Studio Support

  • Visual Studio 2022 (17.x)
  • Visual Studio 2025 (18.x)
  • Visual Studio 2026 (19.x) - Future-proofed

Installation

  1. Download the .vsix file
  2. Double-click to install, or use Visual Studio's "Extensions > Manage Extensions > Install from VSIX"
  3. Restart Visual Studio

Configuration

Access settings via Tools → Options → C# Code Analysis → Cognitive Complexity:

  • Complexity Threshold: Methods above this score show warnings (default: 12)
  • Enable Logging: Turn on detailed logging for troubleshooting (default: off)
  • Polling Interval: How often to check for code changes in seconds (default: 5)

Usage

  1. Open a C# file in Visual Studio
  2. Ensure CodeLens is enabled (Tools → Options → Text Editor → All Languages → CodeLens)
  3. Hover over method names to see cognitive complexity scores
  4. Click the CodeLens indicator for detailed complexity breakdown

Understanding Cognitive Complexity

Cognitive Complexity is a measure of how difficult code is to understand, as defined by Sonar's Cognitive Complexity whitepaper. It considers:

  • Control flow structures (loops, conditionals)
  • Nesting depth
  • Boolean operations
  • Method complexity

Lower scores indicate more readable, maintainable code.

Troubleshooting

Extension Not Loading

  • Ensure CodeLens is enabled in Visual Studio options
  • Check that the extension is properly installed via Extensions Manager
  • Restart Visual Studio after installation

Performance Issues

  • Increase the polling interval in options
  • Disable logging if not needed
  • Consider excluding very large files from analysis

Missing Complexity Scores

  • Ensure the method has a proper signature
  • Check that the file is recognized as C# code
  • Verify CodeLens is enabled for the current document

Version History

v0.31 — First public release

  • Real-time cognitive complexity calculation for C# methods via CodeLens
  • Visual state indicators (good / warning / degraded)
  • Configurable complexity threshold, logging, and polling interval
  • Support for Visual Studio 2022, 2025 (Community, Professional, Enterprise)
  • Support for Visual Studio 2026 (future-proofed)

License

MIT — see license_mit.txt

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2026 Microsoft