|
| 1 | +# PowerShell Localization Extension - Architecture |
| 2 | + |
| 3 | +This document describes the restructured architecture of the PowerShell Localization VS Code extension. |
| 4 | + |
| 5 | +## Architecture Overview |
| 6 | + |
| 7 | +The extension has been restructured following best practices with a modular, maintainable design. The main components are: |
| 8 | + |
| 9 | +### Core Components |
| 10 | + |
| 11 | +#### 1. ExtensionManager (`extensionManager.ts`) |
| 12 | + |
| 13 | +- **Purpose**: Main orchestrator that coordinates all extension components |
| 14 | +- **Responsibilities**: |
| 15 | + - Extension initialization and cleanup |
| 16 | + - Component lifecycle management |
| 17 | + - Configuration change handling |
| 18 | + - File system watching setup |
| 19 | + |
| 20 | +#### 2. Logger (`logger.ts`) |
| 21 | + |
| 22 | +- **Purpose**: Centralized logging utility |
| 23 | +- **Features**: |
| 24 | + - Singleton pattern for consistent logging |
| 25 | + - Multiple log levels (info, error, warn, debug) |
| 26 | + - Timestamped messages |
| 27 | + - VS Code output channel integration |
| 28 | + |
| 29 | +#### 3. ConfigurationManager (`configuration.ts`) |
| 30 | + |
| 31 | +- **Purpose**: Manages extension configuration |
| 32 | +- **Features**: |
| 33 | + - Configuration reading and validation |
| 34 | + - Change event handling |
| 35 | + - Type-safe configuration access |
| 36 | + |
| 37 | +#### 4. PowerShellModuleScanner (`moduleScanner.ts`) |
| 38 | + |
| 39 | +- **Purpose**: Scans and analyzes PowerShell module files |
| 40 | +- **Responsibilities**: |
| 41 | + - Workspace scanning for .psm1 files |
| 42 | + - Import-LocalizedData detection |
| 43 | + - Module information caching |
| 44 | + |
| 45 | +#### 5. PowerShellExecutor (`powershellExecutor.ts`) |
| 46 | + |
| 47 | +- **Purpose**: Executes PowerShell scripts and processes |
| 48 | +- **Features**: |
| 49 | + - PowerShell process management |
| 50 | + - Error handling and logging |
| 51 | + - JSON parsing of script output |
| 52 | + - PowerShell availability checking |
| 53 | + |
| 54 | +#### 6. LocalizationInlineValuesProvider (`inlineValuesProvider.ts`) |
| 55 | + |
| 56 | +- **Purpose**: Provides inline values for localization variables |
| 57 | +- **Features**: |
| 58 | + - Variable and property detection |
| 59 | + - Localization data caching |
| 60 | + - Inline value generation |
| 61 | + - Performance optimization |
| 62 | + |
| 63 | +### Supporting Files |
| 64 | + |
| 65 | +#### 7. Types (`types.ts`) |
| 66 | + |
| 67 | +- **Purpose**: TypeScript type definitions |
| 68 | +- **Contents**: |
| 69 | + - Interface definitions |
| 70 | + - Type aliases |
| 71 | + - Data structure contracts |
| 72 | + |
| 73 | +#### 8. Utils (`utils.ts`) |
| 74 | + |
| 75 | +- **Purpose**: Constants and utility functions |
| 76 | +- **Contents**: |
| 77 | + - Extension constants |
| 78 | + - File type checking utilities |
| 79 | + - Common helper functions |
| 80 | + - Regex patterns |
| 81 | + |
| 82 | +#### 9. Extension Entry Point (`extension.ts`) |
| 83 | + |
| 84 | +- **Purpose**: VS Code extension entry point |
| 85 | +- **Responsibilities**: |
| 86 | + - Extension activation/deactivation |
| 87 | + - Error handling |
| 88 | + - ExtensionManager initialization |
| 89 | + |
| 90 | +## Design Principles |
| 91 | + |
| 92 | +### 1. Single Responsibility Principle |
| 93 | + |
| 94 | +Each class has a single, well-defined responsibility: |
| 95 | + |
| 96 | +- Logger handles only logging |
| 97 | +- ConfigurationManager handles only configuration |
| 98 | +- PowerShellExecutor handles only PowerShell execution |
| 99 | + |
| 100 | +### 2. Dependency Injection |
| 101 | + |
| 102 | +Components receive their dependencies through constructors or method parameters, making testing easier and reducing coupling. |
| 103 | + |
| 104 | +### 3. Error Handling |
| 105 | + |
| 106 | +Comprehensive error handling at each layer: |
| 107 | + |
| 108 | +- Try-catch blocks with proper logging |
| 109 | +- Graceful degradation when components fail |
| 110 | +- User-friendly error messages |
| 111 | + |
| 112 | +### 4. Caching Strategy |
| 113 | + |
| 114 | +- Localization data is cached to improve performance |
| 115 | +- Cache invalidation on file changes |
| 116 | +- Memory-efficient cache management |
| 117 | + |
| 118 | +### 5. Configuration-Driven |
| 119 | + |
| 120 | +- All behaviors can be controlled through VS Code settings |
| 121 | +- Runtime configuration changes are supported |
| 122 | +- Type-safe configuration access |
| 123 | + |
| 124 | +## File Structure |
| 125 | + |
| 126 | +``` |
| 127 | +src/ |
| 128 | +├── extension.ts # Entry point |
| 129 | +├── extensionManager.ts # Main coordinator |
| 130 | +├── types.ts # Type definitions |
| 131 | +├── utils.ts # Constants and utilities |
| 132 | +├── logger.ts # Logging utility |
| 133 | +├── configuration.ts # Configuration management |
| 134 | +├── moduleScanner.ts # PowerShell module scanning |
| 135 | +├── powershellExecutor.ts # PowerShell execution |
| 136 | +├── inlineValuesProvider.ts # Inline values provider |
| 137 | +└── LocalizationParser.ps1 # PowerShell script |
| 138 | +``` |
| 139 | + |
| 140 | +## Benefits of This Architecture |
| 141 | + |
| 142 | +### 1. Maintainability |
| 143 | + |
| 144 | +- Clear separation of concerns |
| 145 | +- Easy to understand and modify |
| 146 | +- Consistent code patterns |
| 147 | + |
| 148 | +### 2. Testability |
| 149 | + |
| 150 | +- Each component can be unit tested independently |
| 151 | +- Dependency injection enables mocking |
| 152 | +- Clear interfaces for testing |
| 153 | + |
| 154 | +### 3. Extensibility |
| 155 | + |
| 156 | +- Easy to add new features |
| 157 | +- Minimal impact when changing existing functionality |
| 158 | +- Well-defined extension points |
| 159 | + |
| 160 | +### 4. Performance |
| 161 | + |
| 162 | +- Efficient caching strategies |
| 163 | +- Lazy loading where appropriate |
| 164 | +- Resource cleanup and disposal |
| 165 | + |
| 166 | +### 5. Robustness |
| 167 | + |
| 168 | +- Comprehensive error handling |
| 169 | +- Graceful degradation |
| 170 | +- Resource management |
| 171 | + |
| 172 | +## Usage Patterns |
| 173 | + |
| 174 | +### Adding New Features |
| 175 | + |
| 176 | +1. Define types in `types.ts` |
| 177 | +2. Add constants to `utils.ts` |
| 178 | +3. Create new service classes following existing patterns |
| 179 | +4. Register with `ExtensionManager` |
| 180 | +5. Add configuration options if needed |
| 181 | + |
| 182 | +### Debugging |
| 183 | + |
| 184 | +- Use the Logger singleton for consistent logging |
| 185 | +- Check the "PowerShell Localization" output channel |
| 186 | +- Enable debug logging for detailed information |
| 187 | + |
| 188 | +### Configuration |
| 189 | + |
| 190 | +- All settings are in the `powershelllocalization` section |
| 191 | +- Changes are automatically detected and applied |
| 192 | +- Type-safe access through `ConfigurationManager` |
0 commit comments