|
| 1 | +# Copilot Instructions |
| 2 | + |
| 3 | +This is the official Prettier VS Code extension (`prettier.prettier-vscode`). It provides code formatting using Prettier for Visual Studio Code, supporting JavaScript, TypeScript, CSS, HTML, Vue, and many other languages. |
| 4 | + |
| 5 | +## Development |
| 6 | + |
| 7 | +- Use `pnpm` as the package manager |
| 8 | +- Run `pnpm install` to install dependencies |
| 9 | +- Run `pnpm webpack` to build for development |
| 10 | +- Run `pnpm test` to run tests (no VS Code instance can be running) |
| 11 | +- Run `pnpm lint` to check linting |
| 12 | +- Run `pnpm prettier` to format code |
| 13 | + |
| 14 | +## Architecture |
| 15 | + |
| 16 | +Entry points: |
| 17 | + |
| 18 | +- Desktop: `src/extension.ts` → bundled to `dist/extension.js` |
| 19 | +- Browser: Same entry, bundled to `dist/web-extension.js` (uses `BrowserModuleResolver` instead of `ModuleResolver`) |
| 20 | + |
| 21 | +Core components: |
| 22 | + |
| 23 | +- `src/extension.ts` - Extension activation, creates ModuleResolver, PrettierEditService, and StatusBar |
| 24 | +- `src/PrettierEditService.ts` - Registers VS Code document formatting providers, handles format requests |
| 25 | +- `src/ModuleResolver.ts` - Resolves local/global Prettier installations, falls back to bundled Prettier |
| 26 | +- `src/PrettierWorkerInstance.ts` - Runs Prettier v3+ in a worker thread for async formatting |
| 27 | +- `src/PrettierMainThreadInstance.ts` - Runs Prettier v2 synchronously on main thread |
| 28 | + |
| 29 | +Webpack produces two bundles: |
| 30 | + |
| 31 | +- Node bundle (`dist/extension.js`) for desktop VS Code |
| 32 | +- Web bundle (`dist/web-extension.js`) for vscode.dev/browser |
| 33 | + |
| 34 | +## Code Style |
| 35 | + |
| 36 | +- Use TypeScript for all source code |
| 37 | +- Follow existing code patterns in the codebase |
| 38 | +- Extension settings are prefixed with `prettier.` and defined in `package.json` |
| 39 | +- Use the VS Code extension API patterns already established in the codebase |
| 40 | + |
| 41 | +## Testing |
| 42 | + |
| 43 | +- Test fixtures live in `test-fixtures/` with their own `package.json` and Prettier configurations |
| 44 | +- The `.do-not-use-prettier-vscode-root` marker file stops module resolver from searching above test fixtures |
| 45 | +- Tests run inside a VS Code instance using the Extension Development Host |
| 46 | + |
| 47 | +## Code Review Guidelines |
| 48 | + |
| 49 | +When reviewing pull requests, focus on: |
| 50 | + |
| 51 | +### Security |
| 52 | + |
| 53 | +- No hardcoded secrets or credentials |
| 54 | +- Workspace Trust is respected when resolving modules from untrusted workspaces |
| 55 | +- User input is validated before use in file paths or module resolution |
| 56 | + |
| 57 | +### VS Code Extension Best Practices |
| 58 | + |
| 59 | +- Disposables are properly registered with `context.subscriptions` to prevent memory leaks |
| 60 | +- Async operations handle errors appropriately |
| 61 | +- User-facing messages go through `LoggingService` or VS Code's message APIs |
| 62 | +- Settings changes are handled correctly (some require reload) |
| 63 | + |
| 64 | +### Prettier Compatibility |
| 65 | + |
| 66 | +- Changes work with both Prettier v2 (sync) and v3+ (async/worker) |
| 67 | +- Module resolution fallback chain is maintained: local → global → bundled |
| 68 | +- Config file watching covers all Prettier config formats |
| 69 | + |
| 70 | +### Performance |
| 71 | + |
| 72 | +- Avoid blocking the extension host main thread |
| 73 | +- Prettier v3+ should use worker threads via `PrettierWorkerInstance` |
| 74 | +- Module and config resolution results are cached appropriately |
| 75 | + |
| 76 | +### Browser Compatibility |
| 77 | + |
| 78 | +- Code in the main bundle should work in both Node.js and browser contexts |
| 79 | +- Browser-specific code uses `BrowserModuleResolver` |
| 80 | +- No Node.js-only APIs in shared code paths |
0 commit comments