Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .claude/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
"permissions": {
"allow": [
"WebFetch(domain:prettier.io)",
"Bash(npm run prettier:*)",
"WebFetch(domain:code.visualstudio.com)",
"Bash(pnpm prettier:*)",
"Bash(pnpm lint:*)",
"mcp__ide__getDiagnostics"
],
"deny": [],
Expand Down
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
},

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "yarn install",
"postCreateCommand": "pnpm install",

// Run as the node user for better security.
"remoteUser": "node"
Expand Down
6 changes: 3 additions & 3 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
## Checklist

- [ ] I have read the [CONTRIBUTING](https://github.com/prettier/prettier-vscode/blob/main/CONTRIBUTING.md) guidelines
- [ ] My code follows the code style of this project (`yarn lint` passes)
- [ ] I have run `yarn prettier` to format my code
- [ ] My code follows the code style of this project (`pnpm lint` passes)
- [ ] I have run `pnpm prettier` to format my code
- [ ] I have added/updated tests that prove my fix or feature works
- [ ] All new and existing tests pass (`yarn test`)
- [ ] All new and existing tests pass (`pnpm test`)
- [ ] I have updated the [CHANGELOG.md](https://github.com/prettier/prettier-vscode/blob/main/CHANGELOG.md) with a summary of my changes
80 changes: 80 additions & 0 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Copilot Instructions

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.

## Development

- Use `pnpm` as the package manager
- Run `pnpm install` to install dependencies
- Run `pnpm webpack` to build for development
- Run `pnpm test` to run tests (no VS Code instance can be running)
- Run `pnpm lint` to check linting
- Run `pnpm prettier` to format code

## Architecture

Entry points:

- Desktop: `src/extension.ts` → bundled to `dist/extension.js`
- Browser: Same entry, bundled to `dist/web-extension.js` (uses `BrowserModuleResolver` instead of `ModuleResolver`)

Core components:

- `src/extension.ts` - Extension activation, creates ModuleResolver, PrettierEditService, and StatusBar
- `src/PrettierEditService.ts` - Registers VS Code document formatting providers, handles format requests
- `src/ModuleResolver.ts` - Resolves local/global Prettier installations, falls back to bundled Prettier
- `src/PrettierWorkerInstance.ts` - Runs Prettier v3+ in a worker thread for async formatting
- `src/PrettierMainThreadInstance.ts` - Runs Prettier v2 synchronously on main thread

Webpack produces two bundles:

- Node bundle (`dist/extension.js`) for desktop VS Code
- Web bundle (`dist/web-extension.js`) for vscode.dev/browser

## Code Style

- Use TypeScript for all source code
- Follow existing code patterns in the codebase
- Extension settings are prefixed with `prettier.` and defined in `package.json`
- Use the VS Code extension API patterns already established in the codebase

## Testing

- Test fixtures live in `test-fixtures/` with their own `package.json` and Prettier configurations
- The `.do-not-use-prettier-vscode-root` marker file stops module resolver from searching above test fixtures
- Tests run inside a VS Code instance using the Extension Development Host

## Code Review Guidelines

When reviewing pull requests, focus on:

### Security

- 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

### VS Code Extension Best Practices

- Disposables are properly registered with `context.subscriptions` to prevent memory leaks
- Async operations handle errors appropriately
- User-facing messages go through `LoggingService` or VS Code's message APIs
- Settings changes are handled correctly (some require reload)

### Prettier Compatibility

- 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

### Performance

- Avoid blocking the extension host main thread
- Prettier v3+ should use worker threads via `PrettierWorkerInstance`
- Module and config resolution results are cached appropriately

### Browser Compatibility

- 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
37 changes: 37 additions & 0 deletions .github/instructions/tests.instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
applyTo: "src/test/**/*.ts"
---

# Test File Guidelines

Tests run inside a VS Code Extension Development Host using Mocha.

## Test Structure

- Use Mocha's `suite()` and `test()` functions
- Import assertions from `assert` module
- Tests interact with real VS Code APIs

## Test Fixtures

- Test fixtures are in `test-fixtures/` directory (not `src/test/`)
- Each fixture has its own `package.json` and Prettier configuration
- Use `getWorkspaceFolderUri(workspaceFolderName)` to get fixture paths
- Fixtures are added to `test.code-workspace` for the test runner

## Formatting Tests

- Use the `format()` helper to open and format documents
- Compare results with `getText()` helper for expected output
- Execute formatting via `vscode.commands.executeCommand("editor.action.formatDocument")`

## Async Patterns

- Tests are async - use `async/await`
- Use `wait()` helper when needing delays
- Prettier v3 formatting is async, may need retries for timing

## Test File Naming

- Name test files as `*.test.ts`
- Group related tests in the same file (e.g., `format.test.ts`, `plugins.test.ts`)
39 changes: 39 additions & 0 deletions .github/instructions/typescript.instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
applyTo: "src/**/*.ts"
---

# TypeScript Source Guidelines

This is a VS Code extension. Follow these patterns:

## Imports

- Import VS Code API from `vscode` module: `import { commands, workspace, window } from "vscode"`
- Use named imports, not namespace imports
- Group imports: vscode first, then node modules, then local modules

## VS Code Extension Patterns

- Use `ExtensionContext.subscriptions` to register disposables for cleanup
- Access settings via `workspace.getConfiguration("prettier")`
- Use `LoggingService` for all logging (not console.log)
- Commands are registered via `commands.registerCommand()`

## Class Patterns

- Services follow dependency injection pattern (pass dependencies via constructor)
- Key services: `LoggingService`, `ModuleResolver`, `PrettierEditService`, `StatusBar`
- Use `Disposable` interface for cleanup

## Prettier Integration

- Support both Prettier v2 (sync, main thread) and v3+ (async, worker thread)
- `PrettierMainThreadInstance` for v2, `PrettierWorkerInstance` for v3+
- Module resolution: local install → global install → bundled Prettier
- Handle `.prettierrc`, `.prettierignore`, and `package.json` prettier config

## Error Handling

- Log errors through `LoggingService`
- Show user-facing errors via `window.showErrorMessage()`
- Handle Workspace Trust restrictions appropriately
39 changes: 39 additions & 0 deletions .github/instructions/workflows.instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
applyTo: ".github/workflows/*.yaml"
---

# GitHub Actions Workflow Guidelines

## Package Manager

- Use `pnpm` as the package manager
- Include `pnpm/action-setup@v4` before running pnpm commands
- Use `actions/setup-node@v6` with `node-version-file: ".nvmrc"`

## Checkout and Setup Pattern

```yaml
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version-file: ".nvmrc"
- uses: pnpm/action-setup@v4
- run: pnpm install
```

## Testing

- Linux tests require Xvfb for display: `/usr/bin/Xvfb :99 -screen 0 1024x768x24`
- Set `DISPLAY: ":99.0"` environment variable for tests on Linux
- Tests run via `pnpm test`

## Permissions

- Use minimal required permissions for each job
- Common permissions: `issues: write`, `pull-requests: write`, `contents: read`

## Scripts in Workflows

- For `actions/github-script@v7`, only use built-in Node.js modules (fs, path, etc.)
- Do not use external npm packages like `js-yaml` in github-script (they are not available)
- Use JSON format for config files that need to be read in workflows
104 changes: 104 additions & 0 deletions .github/labels.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
{
"labels": [
{
"name": "bug",
"color": "#d73a4a",
"description": "Something isn't working"
},
{
"name": "enhancement",
"color": "#a2eeef",
"description": "New feature or request"
},
{
"name": "documentation",
"color": "#0075ca",
"description": "Improvements or additions to documentation"
},
{
"name": "performance",
"color": "#f9d0c4",
"description": "Performance related issues"
},
{
"name": "triage-pending",
"color": "#fbca04",
"description": "Awaiting initial triage"
},
{
"name": "need-more-info",
"color": "#d876e3",
"description": "Further information is requested"
},
{
"name": "stale",
"color": "#ffffff",
"description": "No recent activity"
},
{
"name": "locked",
"color": "#ededed",
"description": "Locked due to inactivity"
},
{
"name": "duplicate",
"color": "#cfd3d7",
"description": "This issue or PR already exists"
},
{
"name": "invalid",
"color": "#e4e669",
"description": "This doesn't seem right"
},
{
"name": "wontfix",
"color": "#ffffff",
"description": "This will not be worked on"
},
{
"name": "help-wanted",
"color": "#008672",
"description": "Extra attention is needed"
},
{
"name": "good-first-issue",
"color": "#7057ff",
"description": "Good for newcomers"
},
{
"name": "pinned",
"color": "#006b75",
"description": "Pinned issue - will not be marked stale"
},
{
"name": "prettier-core",
"color": "#bfdadc",
"description": "Issue is with Prettier core, not the extension"
},
{
"name": "config",
"color": "#c2e0c6",
"description": "Related to configuration"
},
{
"name": "plugin",
"color": "#d4c5f9",
"description": "Related to Prettier plugins"
},
{
"name": "breaking-change",
"color": "#b60205",
"description": "Breaking change"
},
{
"name": "dependencies",
"color": "#0366d6",
"description": "Pull requests that update a dependency"
},
{
"name": "github_actions",
"color": "#000000",
"description": "Pull requests that update GitHub Actions"
}
]
}
Loading
Loading