|
| 1 | +# Copilot Instructions for VS Code Extension Development |
| 2 | + |
| 3 | +## Repository Overview |
| 4 | + |
| 5 | +This repository is a **VS Code extension** written in **TypeScript** and built with **esbuild**. |
| 6 | +The extension currently focuses on **JavaFX/FXML developer experience** (syntax highlighting, |
| 7 | +Scene Builder integration, code navigation, formatting, and outline support for `.fxml` files), |
| 8 | +but the patterns and conventions here are broadly reusable across VS Code extension repositories |
| 9 | +under the `tlcsdm` organization. |
| 10 | + |
| 11 | +--- |
| 12 | + |
| 13 | +## Technology Stack |
| 14 | + |
| 15 | +| Layer | Technology | |
| 16 | +|---|---| |
| 17 | +| Language | TypeScript (strict) | |
| 18 | +| Bundler | esbuild (`esbuild.mjs`) | |
| 19 | +| Linter | ESLint + typescript-eslint (`eslint.config.mjs`) | |
| 20 | +| Test runner | `@vscode/test-cli` + Mocha (`@vscode/test-electron`) | |
| 21 | +| Packaging | `@vscode/vsce` | |
| 22 | +| CI | GitHub Actions (`.github/workflows/`) | |
| 23 | +| Localization | `package.nls.json` + `package.nls.{locale}.json` | |
| 24 | + |
| 25 | +--- |
| 26 | + |
| 27 | +## Project Layout |
| 28 | + |
| 29 | +``` |
| 30 | +src/ TypeScript source files |
| 31 | + extension.ts Entry point — activate() and deactivate() |
| 32 | + *.ts Feature modules (providers, utilities) |
| 33 | + test/ Mocha test suites (run inside VS Code) |
| 34 | +syntaxes/ TextMate grammars (.tmLanguage.json) |
| 35 | +images/ Extension icons and assets |
| 36 | +dist/ Compiled output (git-ignored) |
| 37 | +package.json Extension manifest and contribution points |
| 38 | +package.nls.json English localization strings |
| 39 | +package.nls.zh-cn.json Simplified Chinese strings |
| 40 | +package.nls.ja.json Japanese strings |
| 41 | +language-configuration.json Language bracket/comment rules |
| 42 | +esbuild.mjs Build script |
| 43 | +eslint.config.mjs ESLint configuration |
| 44 | +tsconfig.json TypeScript configuration |
| 45 | +.github/workflows/ CI workflows (build, test, publish, release) |
| 46 | +.github/skills/ Reusable Copilot skill guides (see below) |
| 47 | +``` |
| 48 | + |
| 49 | +--- |
| 50 | + |
| 51 | +## Coordinated Change Rule |
| 52 | + |
| 53 | +> **Whenever you change extension behavior, update ALL of the following that are affected:** |
| 54 | +> |
| 55 | +> 1. `src/` — TypeScript implementation |
| 56 | +> 2. `package.json` — contribution points (commands, configuration, menus, languages, grammars) |
| 57 | +> 3. `package.nls.json` — English localization keys/values |
| 58 | +> 4. `package.nls.zh-cn.json` and other locale files — translated values |
| 59 | +> 5. `README.md` — user-facing documentation |
| 60 | +> 6. `CHANGELOG.md` — release notes entry |
| 61 | +> 7. `src/test/` — unit/integration tests |
| 62 | +
|
| 63 | +Failing to keep these in sync is the most common source of bugs and broken releases. |
| 64 | + |
| 65 | +--- |
| 66 | + |
| 67 | +## Development Workflows |
| 68 | + |
| 69 | +```bash |
| 70 | +# Install dependencies |
| 71 | +npm install |
| 72 | + |
| 73 | +# Type-check without emitting (fast feedback) |
| 74 | +npm run check-types |
| 75 | + |
| 76 | +# Compile for development |
| 77 | +npm run compile |
| 78 | + |
| 79 | +# Watch mode |
| 80 | +npm run watch |
| 81 | + |
| 82 | +# Lint |
| 83 | +npm run lint |
| 84 | + |
| 85 | +# Run tests (requires a display / VS Code instance) |
| 86 | +npm run test |
| 87 | + |
| 88 | +# Production bundle (minified, no source maps) |
| 89 | +npm run package |
| 90 | + |
| 91 | +# Package as .vsix |
| 92 | +npx @vscode/vsce package |
| 93 | +``` |
| 94 | + |
| 95 | +--- |
| 96 | + |
| 97 | +## Coding Conventions |
| 98 | + |
| 99 | +### TypeScript |
| 100 | +- All files use **strict TypeScript** (`tsconfig.json` enforces this). |
| 101 | +- Prefer `const` and `readonly`; avoid `any`. |
| 102 | +- Use `vscode.ExtensionContext.subscriptions.push(...)` for all disposables registered in `activate()`. |
| 103 | +- Never store global mutable state; thread context through function parameters or classes. |
| 104 | +- Export only what is needed by other modules; keep internals `private` or unexported. |
| 105 | + |
| 106 | +### Naming |
| 107 | +- Commands: `<publisher>.<extensionName>.<verb><Object>` — e.g., `tlcsdm.javafxSupport.openInSceneBuilder` |
| 108 | +- Configuration keys: `<publisher>.<extensionName>.<section>.<key>` — e.g., `tlcsdm.javafxSupport.sceneBuilderPath` |
| 109 | +- TypeScript classes: `PascalCase`; functions and variables: `camelCase` |
| 110 | + |
| 111 | +### Error Handling |
| 112 | +- Surface errors to users via `vscode.window.showErrorMessage(...)`, not bare `console.error`. |
| 113 | +- Use `vscode.window.showWarningMessage(...)` for recoverable issues. |
| 114 | +- Catch and handle promise rejections; do not let unhandled rejections crash the extension host. |
| 115 | + |
| 116 | +### Localization |
| 117 | +- Every user-facing string in `package.json` must use a `%key%` placeholder. |
| 118 | +- The key must exist in `package.nls.json` (English), and a best-effort translation in every other locale file. |
| 119 | +- Strings inside TypeScript source are currently inline; use `vscode.l10n.t(...)` for new strings if i18n is needed in code. |
| 120 | + |
| 121 | +### Provider Pattern |
| 122 | +- Implement VS Code provider interfaces (`vscode.DefinitionProvider`, `vscode.DocumentSymbolProvider`, etc.) as named classes in dedicated files. |
| 123 | +- Register providers in `activate()` via `context.subscriptions.push(vscode.languages.register*(...))`. |
| 124 | +- Keep provider logic pure and testable; avoid side effects in provider methods. |
| 125 | + |
| 126 | +### Menus and When-Clauses |
| 127 | +- Use the narrowest `when` clause possible for menu contributions. |
| 128 | +- Prefer built-in context keys (`resourceLangId`, `editorLangId`) over custom context keys where sufficient. |
| 129 | + |
| 130 | +### Commit Messages |
| 131 | +- Follow the **Angular commit convention** for all commits. |
| 132 | +- Use the format: `<type>(<scope>): <subject>` when a scope is helpful, or `<type>: <subject>` when it is not. |
| 133 | +- Prefer common types such as `feat`, `fix`, `docs`, `refactor`, `test`, `build`, `ci`, `style` and `chore`. |
| 134 | +- Keep the subject concise, imperative, and lowercase where practical. |
| 135 | +- Examples: |
| 136 | + - `feat(fxml): add controller navigation` |
| 137 | + - `fix(scene-builder): handle missing executable path` |
| 138 | + - `docs(copilot): add vscode extension skill guidance` |
| 139 | + |
| 140 | +--- |
| 141 | + |
| 142 | +## Extension Activation |
| 143 | + |
| 144 | +- `activationEvents` in `package.json` controls when the extension loads. |
| 145 | +- Prefer `onLanguage:<id>` events over `*` (eager activation) to reduce startup impact. |
| 146 | +- Keep `activate()` fast: defer expensive work (file system scans, network calls) using lazy initialization or `onDidOpenTextDocument`. |
| 147 | + |
| 148 | +--- |
| 149 | + |
| 150 | +## Security Considerations |
| 151 | + |
| 152 | +- Never execute untrusted user input as shell commands without validation and escaping. |
| 153 | +- When spawning child processes (e.g., launching Scene Builder), sanitize all path arguments. |
| 154 | +- Do not write to arbitrary file system paths based on user or workspace input without confirmation. |
| 155 | +- Avoid `eval` and dynamic `require` inside the extension bundle. |
| 156 | + |
| 157 | +--- |
| 158 | + |
| 159 | +## Skills Reference |
| 160 | + |
| 161 | +Detailed, reusable guides are in `.github/skills/`. Consult them when working on these areas: |
| 162 | + |
| 163 | +| Topic | File | |
| 164 | +|---|---| |
| 165 | +| Extension architecture & patterns | `.github/skills/vscode-extension-architecture/SKILL.md` | |
| 166 | +| `package.json` contribution points | `.github/skills/vscode-package-json-and-contributes/SKILL.md` | |
| 167 | +| Commands & activation | `.github/skills/vscode-commands-and-activation/SKILL.md` | |
| 168 | +| Language features & providers | `.github/skills/vscode-language-features/SKILL.md` | |
| 169 | +| Webviews & native VS Code UI | `.github/skills/vscode-webview-and-ui/SKILL.md` | |
| 170 | +| Configuration & settings | `.github/skills/vscode-configuration-and-settings/SKILL.md` | |
| 171 | +| Testing & debugging | `.github/skills/vscode-testing-and-debugging/SKILL.md` | |
| 172 | +| Build, packaging & release | `.github/skills/vscode-build-package-and-release/SKILL.md` | |
| 173 | +| i18n & documentation | `.github/skills/vscode-i18n-and-docs/SKILL.md` | |
| 174 | +| Performance & compatibility | `.github/skills/vscode-performance-and-compatibility/SKILL.md` | |
| 175 | +| Refactoring & maintenance | `.github/skills/vscode-refactor-and-maintenance/SKILL.md` | |
0 commit comments