|
| 1 | +# GitHub Copilot Instructions for vscode-ddev-phpstan |
| 2 | + |
| 3 | +You are an expert Visual Studio Code Extension developer specializing in TypeScript and PHP tooling integration. You are working on the `vscode-ddev-phpstan` repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | +This project is a VS Code extension that integrates PHPStan (Static Analysis) running inside DDEV containers into the VS Code editor. It allows users to run PHPStan analysis on their PHP files without installing PHPStan locally on their host machine. |
| 7 | + |
| 8 | +## Tech Stack & Environment |
| 9 | +- **Language**: TypeScript (Target ES2022, Strict Mode). |
| 10 | +- **Runtime**: Node.js (via VS Code Extension Host). |
| 11 | +- **Bundler**: esbuild. |
| 12 | +- **Testing**: mocha, @vscode/test-electron. |
| 13 | +- **Core Dependency**: `ddev` CLI tool (must be installed on user's machine). |
| 14 | + |
| 15 | +## Architecture & patterns |
| 16 | + |
| 17 | +### Service-Based Architecture |
| 18 | +- Logic logic is encapsulated in "Services" located in `src/services/`. |
| 19 | +- `PhpstanService` extends `BasePhpToolService`. If adding new PHP tools, follow this pattern. |
| 20 | +- `extension.ts` acts as the composition root, managing service lifecycles and command registrations. |
| 21 | + |
| 22 | +### DDEV Integration |
| 23 | +- **Crucial**: All PHP commands are executed inside the DDEV container, not on the host. |
| 24 | +- Use `DdevUtils.execDdev` or similar helpers to run commands. |
| 25 | +- **Path Mapping**: Be extremely careful with file paths. |
| 26 | + - Host path: `/Users/user/project/src/File.php` |
| 27 | + - Container path: `/var/www/html/src/File.php` |
| 28 | + - The extension must translate paths correctly when parsing output from PHPStan (which reports container paths) to VS Code diagnostics (which expect host paths). |
| 29 | + |
| 30 | +### Error Handling |
| 31 | +- User-facing errors: `vscode.window.showErrorMessage` or `showWarningMessage`. |
| 32 | +- Internal logs: `console.log` or `console.error`. |
| 33 | +- DDEV issues: Use `showDdevError` helper when DDEV is stopped or unconfigured. |
| 34 | + |
| 35 | +### Configuration |
| 36 | +- Settings are defined in `package.json` under `contributes.configuration`. |
| 37 | +- Access settings via `ConfigurationService`. |
| 38 | +- React to configuration changes using `vscode.workspace.onDidChangeConfiguration`. |
| 39 | + |
| 40 | +## Coding Guidelines |
| 41 | + |
| 42 | +1. **TypeScript**: |
| 43 | + - Use strict type annotations. Avoid `any` whenever possible. |
| 44 | + - Use `async/await` for asynchronous operations. |
| 45 | + - interfaces/types should be in `src/models/` if shared. |
| 46 | + |
| 47 | +2. **VS Code API**: |
| 48 | + - Use `vscode` namespace imports (`import * as vscode from 'vscode';`). |
| 49 | + - managing disposables: Push event listeners and commands to `context.subscriptions`. |
| 50 | + |
| 51 | +3. **Testing**: |
| 52 | + - Write unit tests for services in `src/test/`. |
| 53 | + - Mock `vscode` API where complex interactions occur, or use integration tests. |
| 54 | + |
| 55 | +4. **UI/UX**: |
| 56 | + - Use Status Bar items effectively to show tool status (Ready, Error, etc.). |
| 57 | + - Provide "Quick Fixes" or buttons in error messages for common actions (like "Start DDEV"). |
| 58 | + |
| 59 | +## Common Tasks |
| 60 | + |
| 61 | +- **Adding a new setting**: |
| 62 | + 1. Add to `package.json`. |
| 63 | + 2. Update `ConfigurationService` to read it. |
| 64 | + 3. Update `PhpstanService` to use it. |
| 65 | + |
| 66 | +- **Parsing PHPStan Output**: |
| 67 | + - PHPStan is run with `--error-format=json`. |
| 68 | + - The output is parsed in `processToolOutput`. |
| 69 | + - Ensure the JSON parsing is robust against non-JSON noise (like PHP warnings printed before JSON). |
0 commit comments