This document describes the restructured architecture of the PowerShell Localization VS Code extension.
The extension has been restructured following best practices with a modular, maintainable design. The main components are:
- Purpose: Main orchestrator that coordinates all extension components
- Responsibilities:
- Extension initialization and cleanup
- Component lifecycle management
- Configuration change handling
- File system watching setup
- Purpose: Centralized logging utility
- Features:
- Singleton pattern for consistent logging
- Multiple log levels (info, error, warn, debug)
- Timestamped messages
- VS Code output channel integration
- Purpose: Manages extension configuration
- Features:
- Configuration reading and validation
- Change event handling
- Type-safe configuration access
- Purpose: Scans and analyzes PowerShell module files
- Responsibilities:
- Workspace scanning for .psm1 files
- Import-LocalizedData detection
- Module information caching
- Purpose: Executes PowerShell scripts and processes
- Features:
- PowerShell process management
- Error handling and logging
- JSON parsing of script output
- PowerShell availability checking
- Purpose: Provides inline values for localization variables
- Features:
- Variable and property detection
- Localization data caching
- Inline value generation
- Performance optimization
- Purpose: TypeScript type definitions
- Contents:
- Interface definitions
- Type aliases
- Data structure contracts
- Purpose: Constants and utility functions
- Contents:
- Extension constants
- File type checking utilities
- Common helper functions
- Regex patterns
- Purpose: VS Code extension entry point
- Responsibilities:
- Extension activation/deactivation
- Error handling
- ExtensionManager initialization
Each class has a single, well-defined responsibility:
- Logger handles only logging
- ConfigurationManager handles only configuration
- PowerShellExecutor handles only PowerShell execution
Components receive their dependencies through constructors or method parameters, making testing easier and reducing coupling.
Comprehensive error handling at each layer:
- Try-catch blocks with proper logging
- Graceful degradation when components fail
- User-friendly error messages
- Localization data is cached to improve performance
- Cache invalidation on file changes
- Memory-efficient cache management
- All behaviors can be controlled through VS Code settings
- Runtime configuration changes are supported
- Type-safe configuration access
src/
├── extension.ts # Entry point
├── extensionManager.ts # Main coordinator
├── types.ts # Type definitions
├── utils.ts # Constants and utilities
├── logger.ts # Logging utility
├── configuration.ts # Configuration management
├── moduleScanner.ts # PowerShell module scanning
├── powershellExecutor.ts # PowerShell execution
├── inlineValuesProvider.ts # Inline values provider
└── LocalizationParser.ps1 # PowerShell script
- Clear separation of concerns
- Easy to understand and modify
- Consistent code patterns
- Each component can be unit tested independently
- Dependency injection enables mocking
- Clear interfaces for testing
- Easy to add new features
- Minimal impact when changing existing functionality
- Well-defined extension points
- Efficient caching strategies
- Lazy loading where appropriate
- Resource cleanup and disposal
- Comprehensive error handling
- Graceful degradation
- Resource management
- Define types in
types.ts - Add constants to
utils.ts - Create new service classes following existing patterns
- Register with
ExtensionManager - Add configuration options if needed
- Use the Logger singleton for consistent logging
- Check the "PowerShell Localization" output channel
- Enable debug logging for detailed information
- All settings are in the
powershelllocalizationsection - Changes are automatically detected and applied
- Type-safe access through
ConfigurationManager