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.
- Use
npmas the package manager - Run
npm installto install dependencies - Run
npm run compileto build for development - Run
npm run testto run tests (no VS Code instance can be running) - Run
npm run lintto check linting - Run
npm run prettierto format code
Entry points:
- Desktop:
src/extension.ts→ bundled todist/extension.js - Browser: Same entry, bundled to
dist/web-extension.js(usesBrowserModuleResolverinstead ofModuleResolver)
Core components:
src/extension.ts- Extension activation, creates ModuleResolver, PrettierEditService, and StatusBarsrc/PrettierEditService.ts- Registers VS Code document formatting providers, handles format requestssrc/ModuleResolver.ts- Resolves local/global Prettier installations, falls back to bundled Prettiersrc/PrettierInstance.ts- Interface for Prettier loading, withPrettierMainThreadInstanceandPrettierWorkerInstanceimplementations
esbuild produces two bundles:
- Node bundle (
dist/extension.js) for desktop VS Code - Web bundle (
dist/web-extension.js) for vscode.dev/browser
- Use TypeScript for all source code
- Follow existing code patterns in the codebase
- Extension settings are prefixed with
prettier.and defined inpackage.json - Use the VS Code extension API patterns already established in the codebase
- Test fixtures live in
test-fixtures/with their ownpackage.jsonand Prettier configurations - The
.do-not-use-prettier-vscode-rootmarker file stops module resolver from searching above test fixtures - Tests run inside a VS Code instance using the Extension Development Host
When reviewing pull requests, focus on:
- No hardcoded secrets or credentials
- Workspace Trust is respected when resolving modules from untrusted workspaces
- User input is validated before use in file paths or module resolution
- Disposables are properly registered with
context.subscriptionsto prevent memory leaks - Async operations handle errors appropriately
- User-facing messages go through
LoggingServiceor VS Code's message APIs - Settings changes are handled correctly (some require reload)
- Changes work with both Prettier v2 (sync) and v3+ (async/worker)
- Module resolution fallback chain is maintained: local → global → bundled
- Config file watching covers all Prettier config formats
- Avoid blocking the extension host main thread
PrettierWorkerInstanceruns Prettier in a worker thread to avoid blocking- Module and config resolution results are cached appropriately
- Code in the main bundle should work in both Node.js and browser contexts
- Browser-specific code uses
BrowserModuleResolver - No Node.js-only APIs in shared code paths