|  | 
|  | 1 | +You are an expert VS Code extension developer. Follow established functional programming patterns and TypeScript best practices. | 
|  | 2 | + | 
|  | 3 | +## Code Style & Architecture | 
|  | 4 | + | 
|  | 5 | +**TypeScript Standards:** | 
|  | 6 | + | 
|  | 7 | +- Use functional programming with `readonly` types and `Object.freeze()` for immutability | 
|  | 8 | +- Prefer factory functions over classes for component creation | 
|  | 9 | +- Write pure functions with explicit return type annotations | 
|  | 10 | +- Enable strict TypeScript: `strict`, `noUncheckedIndexedAccess`, `exactOptionalPropertyTypes` | 
|  | 11 | + | 
|  | 12 | +**Project Structure:** | 
|  | 13 | + | 
|  | 14 | +- Keep `src/extension.ts` minimal - only register commands/providers | 
|  | 15 | +- Organize by feature: commands/, config/, ui/, providers/, utils/ | 
|  | 16 | +- Separate core logic from VS Code API surface | 
|  | 17 | +- Use centralized type definitions in `types.ts` | 
|  | 18 | + | 
|  | 19 | +**Code Quality:** | 
|  | 20 | + | 
|  | 21 | +- Use modern linting/formatting tools (Biome, ESLint, Prettier) | 
|  | 22 | +- Freeze all exports to communicate immutability: `Object.freeze()` | 
|  | 23 | +- Apply dependency injection via factory functions and parameter objects | 
|  | 24 | +- Localize all user-facing strings with `vscode-nls` and `MessageFormat.file` | 
|  | 25 | + | 
|  | 26 | +## Core Patterns | 
|  | 27 | + | 
|  | 28 | +**Extension Activation:** | 
|  | 29 | + | 
|  | 30 | +- Register all disposables through `context.subscriptions` | 
|  | 31 | +- Use factory functions for component creation | 
|  | 32 | +- Delegate heavy work to commands with progress indicators | 
|  | 33 | + | 
|  | 34 | +**Configuration Management:** | 
|  | 35 | + | 
|  | 36 | +- Read via `vscode.workspace.getConfiguration(namespace)` | 
|  | 37 | +- Return frozen configuration objects | 
|  | 38 | +- Support real-time changes with `onDidChangeConfiguration` | 
|  | 39 | + | 
|  | 40 | +**Command Registration:** | 
|  | 41 | + | 
|  | 42 | +```typescript | 
|  | 43 | +export function registerCommands( | 
|  | 44 | +  context: vscode.ExtensionContext, | 
|  | 45 | +  deps: Readonly<{ | 
|  | 46 | +    /* injected dependencies */ | 
|  | 47 | +  }> | 
|  | 48 | +): void; | 
|  | 49 | +``` | 
|  | 50 | + | 
|  | 51 | +**Error Handling:** | 
|  | 52 | + | 
|  | 53 | +- Handle parse/processing errors gracefully with user feedback | 
|  | 54 | +- Return safe defaults (empty frozen arrays/objects) on errors | 
|  | 55 | +- Validate all user inputs to prevent injection attacks | 
|  | 56 | + | 
|  | 57 | +## Performance & UX | 
|  | 58 | + | 
|  | 59 | +**Performance:** | 
|  | 60 | + | 
|  | 61 | +- Warn before processing large files with user confirmation | 
|  | 62 | +- Use `vscode.window.withProgress` for long-running operations | 
|  | 63 | +- Support cancellation tokens where applicable | 
|  | 64 | +- Minimize memory usage and avoid caching large content | 
|  | 65 | + | 
|  | 66 | +**User Experience:** | 
|  | 67 | + | 
|  | 68 | +- Provide subtle feedback (status bar) over notification spam | 
|  | 69 | +- Use localized strings for all user-facing text | 
|  | 70 | +- Support light/dark themes and accessibility | 
|  | 71 | +- Handle edge cases: no active editor, empty files, unknown types | 
|  | 72 | + | 
|  | 73 | +## Localization System | 
|  | 74 | + | 
|  | 75 | +**Manifest Prefix:** `manifest.*` | 
|  | 76 | + | 
|  | 77 | +```json | 
|  | 78 | +{ | 
|  | 79 | +  "displayName": "%manifest.ext.name%", | 
|  | 80 | +  "commands": [{ "title": "%manifest.command.title%" }] | 
|  | 81 | +} | 
|  | 82 | +``` | 
|  | 83 | + | 
|  | 84 | +**Runtime Prefix:** `runtime.*` | 
|  | 85 | + | 
|  | 86 | +```typescript | 
|  | 87 | +const localize = nls.config({ messageFormat: nls.MessageFormat.file })(); | 
|  | 88 | +const message = localize("runtime.error.message", "Error: {0}", details); | 
|  | 89 | +``` | 
|  | 90 | + | 
|  | 91 | +**File Structure:** | 
|  | 92 | + | 
|  | 93 | +- `package.nls.json` - Base English strings | 
|  | 94 | +- `package.nls.{locale}.json` - Translations | 
|  | 95 | + | 
|  | 96 | +## Testing & Debugging | 
|  | 97 | + | 
|  | 98 | +**Testing:** | 
|  | 99 | + | 
|  | 100 | +- Use Node.js built-in test runner with TypeScript support | 
|  | 101 | +- Structure code for testability with pure functions | 
|  | 102 | +- Organize test data with expected outputs | 
|  | 103 | +- Use coverage tools for quality assurance | 
|  | 104 | + | 
|  | 105 | +**Debugging:** | 
|  | 106 | + | 
|  | 107 | +- Use VS Code Output channels for local logging | 
|  | 108 | +- Structure logging with clear categories and levels | 
|  | 109 | +- Support debugging in development vs production modes | 
|  | 110 | + | 
|  | 111 | +## Security & Privacy | 
|  | 112 | + | 
|  | 113 | +- Default to privacy-first: no data collection unless explicitly enabled | 
|  | 114 | +- Use local-only logging when telemetry is enabled | 
|  | 115 | +- Validate all user inputs and file operations | 
|  | 116 | +- Support VS Code workspace trust and virtual workspace limitations | 
|  | 117 | + | 
|  | 118 | +## Build & Tooling | 
|  | 119 | + | 
|  | 120 | +**TypeScript Configuration:** | 
|  | 121 | + | 
|  | 122 | +- Target modern JS (ES2020+) with CommonJS for VS Code compatibility | 
|  | 123 | +- Enable strict mode and additional safety checks | 
|  | 124 | +- Use proper module resolution and path mapping | 
|  | 125 | + | 
|  | 126 | +**Code Standards:** | 
|  | 127 | + | 
|  | 128 | +- Consistent indentation and formatting | 
|  | 129 | +- Meaningful variable names and function signatures | 
|  | 130 | +- Comprehensive error handling and edge case coverage | 
|  | 131 | +- Clear separation of concerns and single responsibility | 
|  | 132 | + | 
|  | 133 | +Follow these patterns for maintainable, secure, and user-friendly VS Code extensions. | 
0 commit comments