Code Annotation - VS Code Extension
A powerful VS Code extension for educational code annotations that provides contextual tooltips, CodeLens indicators, interactive sidebar navigation, and rich webview panels to enhance coding education and documentation.
🎯 What This Extension Does
Code Annotation transforms static code into an interactive learning experience by overlaying educational annotations directly onto your source code through multiple visual interfaces:
🔍 Multiple Annotation Views
- 📝 CodeLens Integration: Inline indicators showing annotation count and status at each annotated line
- 🖱️ Rich Hover Tooltips: Detailed markdown-formatted content with syntax highlighting when you hover over code
- 🗂️ Interactive Sidebar: Navigate all annotations in the current file with smart sorting and filtering
- 📋 Webview Panels: Full-featured annotation viewer with copy/export capabilities
⚡ Real-time Pattern Matching
- Smart Triggers: Annotations appear when you save files (Ctrl+S) or switch between files
- Multi-language Support: JavaScript, TypeScript, Python, Java, C#, Go, Rust
- Pattern Types: Regular expressions, literal text, substring matching, and multi-line code blocks
- Hierarchical Logic: Nested annotations with intelligent containment detection
📊 Progress Tracking & Analytics
- View Status: Visual indicators (✅/⚠️) showing which annotations you've seen
- Smart Status Bar: Live progress counter showing "🗄 X new, Y viewed"
- Performance Dashboard: Cache statistics, query performance, and detailed analytics
- Progress Reset: Commands to reset viewing progress per file or globally
🚀 Key Features
Visual Discovery System
- CodeLens Indicators: Each annotated line shows a clickable indicator like
⚠️ Course Tip (new) at the end of the line
- Hover Integration: Rich tooltips with course branding, code examples, and metadata
- Smart Highlighting: Precise code highlighting for single-line and multi-line annotations
- Theme Adaptive: Icons and colors automatically adapt to VS Code light/dark themes
Advanced Pattern Engine
- Flexible Regex: Automatic whitespace normalization for robust code matching
- Multi-line Code Blocks: Annotations can span multiple lines with precise range detection
- Priority System: Higher priority annotations take precedence when multiple patterns match
- Performance Optimized: Multi-layer caching (L1: document scans, L2: metadata, L3: compiled patterns)
Interactive Annotation Experience
- Click Actions: When you click a CodeLens indicator, choose from:
- 📋 Rich Webview: Full-featured panel with formatted content
- 👁️ Quick Preview: Information popup with summary
- 📝 Copy to Clipboard: Export annotation content
- 🖱️ Hover Trigger: Show hover tooltip at cursor position
Course-Level Customization
- Custom Branding: Course name, headers, tip labels (e.g. "Rust Expert Tip", "Pro Tip")
- Custom Icons: SVG icons in hover tooltips and webviews
- Database Metadata: Store course information and branding alongside annotations
🛠️ How It Works
For Students
- Install Extension: Get Code Annotation from VS Code Marketplace
- Load Database: Command Palette →
Code Annotation: Select Annotations Database
- Start Learning: Open source files - annotations automatically appear as you code
- Explore Content: Click CodeLens indicators, hover over highlighted code, or browse the sidebar
For Educators
- Create Annotations: Author content in YAML format with pattern definitions
- Build Database: Use companion tools to convert YAML to SQLite database
- Test & Refine: Load database in VS Code to preview annotations
- Distribute: Share the
.db file with students
📋 Available Commands
All commands are available through Command Palette (Ctrl+Shift+P ):
Command |
Description |
When Available |
Code Annotation: Select Annotations Database |
Choose a .db file to load |
Always |
Code Annotation: Show Annotation Stats |
View progress, course info, and performance data |
When database loaded |
Code Annotation: Refresh Annotations |
Re-scan current file for new annotations |
When database loaded |
Code Annotation: Reset All Progress |
Clear all viewing progress |
When database loaded |
Code Annotation: Reset File Progress |
Clear progress for current file only |
When database loaded |
Code Annotation: Disconnect Database |
Unload current database |
When database loaded |
Code Annotation: Show Performance Dashboard |
View detailed performance analytics |
Always |
Code Annotation: Test Cache Performance |
Run cache performance diagnostics |
When database loaded |
💾 Status Bar Integration
The status bar provides real-time feedback:
⛔ No Annotations DB - No database loaded (click to select one)
⏳ [████░░░░] 45% - Loading progress with animated progress bar
🗄 5 new, 8 viewed - Live annotation progress (click for options menu)
⚙️ Settings
Configure the extension through VS Code settings:
Setting |
Description |
Default |
codeAnnotations.autoScanOnOpen |
Automatically scan files when opened |
true |
codeAnnotations.databasePath |
Path to current annotations database |
"" |
codeAnnotations.progression |
Progress tracking data (internal) |
{} |
🔧 Technical Architecture
- Multi-Layer Caching: Document scan results cached with version-based invalidation
- Smart Scanning: Only processes supported file types and respects file save triggers
- Optimized Queries: SQLite database with indexed queries for sub-5ms response times
- Memory Efficient: Compiled regex patterns cached, document content not stored
Advanced Pattern Matching
- Flexible Processing: Automatic whitespace normalization for robust code matching
- Multi-line Support: Code block patterns can span multiple lines with precise range detection
- Hierarchical Logic: Nested annotation detection with intelligent containment relationships
- Language Filtering: Annotations filtered by file language for improved performance
Event-Driven Architecture
- Primary Trigger: File save events (Ctrl+S) trigger annotation discovery
- Secondary Trigger: Active editor changes (with configurable auto-scan)
- Cache Invalidation: Document changes invalidate cached results automatically
- Progress Sync: Real-time synchronization between CodeLens, sidebar, and status bar
📂 Extension Structure
The extension consists of several key components:
- AnnotationManager: Core database interface and pattern matching engine
- CodeLens Provider: Inline indicators at the end of annotated lines
- Hover Provider: Rich tooltips with markdown content and code highlighting
- Sidebar Provider: Tree view with clickable annotation navigation
- Decoration Manager: Code highlighting and visual feedback
- Performance Dashboard: Analytics and diagnostics interface
🏗️ Database Schema
The SQLite database contains:
- course_metadata: Course name, branding, custom tip labels, icons
- annotations: Pattern definitions, content, languages, priority, tags
- Optimized Indexes: Fast querying by language, pattern type, and priority
🎨 Supported Languages
- JavaScript & TypeScript - Full syntax support with JSX/TSX
- Python - All language constructs and patterns
- Java & C# - Object-oriented pattern matching
- Go & Rust - Modern systems programming languages
- Universal: Pattern matching works with any text-based language
Typical performance characteristics:
- Database Load: ~50ms initial load for 1000+ annotations
- Document Scan: ~5-15ms per file save
- Pattern Matching: ~0.1ms per line per annotation
- Memory Usage: ~1MB for large annotation databases
- Cache Hit Ratio: >90% for repeated operations
🔍 Development & Debugging
Built-in Diagnostics
- Performance Dashboard: Real-time statistics and cache performance
- Cache Testing: Built-in tools to test cache performance and invalidation
- Console Logging: Detailed timing information for all operations
- Error Handling: Graceful fallbacks with informative error messages
Extension Development
# Compile TypeScript
npm run compile
# Watch for changes during development
npm run watch
# Debug: Press F5 in VS Code to launch Extension Development Host
# Load your .db file and test annotations in the debug environment
📈 Analytics & Insights
The extension provides rich analytics:
- Annotation Discovery: Track which annotations students find and engage with
- Performance Metrics: Cache hit ratios, query timing, memory usage
- Usage Patterns: Most viewed annotations, file-level engagement
- Error Tracking: Pattern matching failures and database issues
🤝 Integration Ecosystem
This VS Code extension is part of a larger educational toolkit:
- YAML Authoring: Human-readable annotation format for content creators
- Build Pipeline: Tools to convert YAML annotations to optimized SQLite databases
- AI-Powered Generation: MCP (Model Context Protocol) integration for automated annotation creation
- Cross-Platform: Database format designed for potential future IDE support
Built for Education. Optimized for Performance. Designed for Scale.
Transform your codebase into an interactive learning experience with Code Annotation.
| |