|
1 | 1 | # Copilot Instructions for vscode-powershell |
2 | 2 |
|
3 | | -## Updating NPM Packages |
4 | | - |
5 | | -- Read [docs/development.md](../docs/development.md) "Tracking Upstream Dependencies" first |
6 | | -- Dependencies are split: `dependencies` + `devDependencies` for build, `optionalDependencies` for lint/test |
7 | | -- Remember to use `npm install --include=optional` since we also need to update lint and test dependencies |
8 | | -- The `.npmrc` uses an Azure Artifacts mirror; read its comments for authentication instructions |
9 | | -- After updating, verify: `npm run compile` (build), `npm run lint` (lint), `npm audit` (security) |
10 | | -- The ESLint packages (`eslint`, `@eslint/js`, `typescript-eslint`, `eslint-config-prettier`) should be updated together |
11 | | -- Fix any new lint warnings from updates to ESLint |
12 | | -- Use `npm audit` to identify vulnerabilities |
13 | | -- Do not use `npm audit fix --force` when a vulnerability is in a transitive dependency, instead add an `overrides` entry |
| 3 | +This is the VS Code extension for PowerShell — an LSP client that communicates with |
| 4 | +[PowerShellEditorServices][] (PSES), the LSP server. The extension manages the PSES process |
| 5 | +lifecycle, provides UI features, and handles debugging. |
| 6 | + |
| 7 | +[PowerShellEditorServices]: https://github.com/PowerShell/PowerShellEditorServices |
| 8 | + |
| 9 | +## Build, Lint, and Test |
| 10 | + |
| 11 | +```sh |
| 12 | +npm install --include=optional # Install all deps (lint/test tools are in optionalDependencies) |
| 13 | +npm run compile # Build with esbuild (outputs to dist/) |
| 14 | +npm run lint # ESLint (strict TypeScript-aware rules) |
| 15 | +npm run format # Prettier check (with organize-imports plugin) |
| 16 | +npm test # Integration tests via @vscode/test-cli |
| 17 | +``` |
| 18 | + |
| 19 | +After any code change, always run `npm run compile`, `npm run lint`, and `npm run format`. Tests run inside a VS Code Insiders instance — there is no way to run a |
| 20 | +single test from the command line. Tests live in `test/` mirroring `src/` structure and use |
| 21 | +Mocha BDD (`describe`/`it`). |
| 22 | + |
| 23 | +## Architecture |
| 24 | + |
| 25 | +`activate()` in `src/extension.ts` creates the `Logger`, `SessionManager`, and two groups of |
| 26 | +features: |
| 27 | + |
| 28 | +1. **Standalone features** — commands that don't need the LSP client (e.g. `PesterTestsFeature`) |
| 29 | +2. **LanguageClientConsumers** — features extending `LanguageClientConsumer` that depend on the |
| 30 | + LSP client and override `onLanguageClientSet()` to register their handlers |
| 31 | + |
| 32 | +`SessionManager` (`src/session.ts`) owns the full lifecycle: finding a PowerShell executable |
| 33 | +(`src/platform.ts`), spawning PSES (`src/process.ts`), connecting the `LanguageClient`, and |
| 34 | +restarting on critical setting changes. |
| 35 | + |
| 36 | +Each feature in `src/features/` exports one `vscode.Disposable` class. Custom LSP message |
| 37 | +types are defined as `RequestType`/`NotificationType` constants in the same file. |
| 38 | +`IPowerShellExtensionClient` in `src/features/ExternalApi.ts` is the public API for other |
| 39 | +extensions. |
| 40 | + |
| 41 | +### PSES and Cross-Repo Work |
| 42 | + |
| 43 | +The `modules/` folder contains the PSES, PSReadLine, and PSScriptAnalyzer PowerShell modules. In development it is a |
| 44 | +symlink to `../PowerShellEditorServices/module` — [PowerShellEditorServices][] must be |
| 45 | +cloned as a sibling and built before `npm run compile` will succeed. For cross-repo work, use `pwsh-extension-dev.code-workspace`. |
| 46 | + |
| 47 | +## Key Conventions |
| 48 | + |
| 49 | +- **VS Code best practices**: Follow the [Extension Guidelines](https://code.visualstudio.com/api/references/extension-guidelines) and [UX Guidelines](https://code.visualstudio.com/api/ux-guidelines/overview). Use VS Code's APIs idiomatically and prefer disposable patterns for lifecycle management. |
| 50 | +- **Logging**: Use `ILogger` (not `console.log`). Tests use `TestLogger` from `test/utils.ts`. |
| 51 | +- **Settings**: Defined in `package.json` under `contributes.configuration`, read via |
| 52 | + `vscode.workspace.getConfiguration("powershell")` at point of use. Helpers in `src/settings.ts`. |
| 53 | +- **TypeScript**: Strict mode, ESNext, `verbatimModuleSyntax`. `explicit-function-return-type` |
| 54 | + enforced. Unused vars prefixed `_`. Formatting via Prettier with the `organize-imports` |
| 55 | + plugin. Use `import x = require("x")` for Node/VS Code built-ins. |
| 56 | +- **File headers**: Every source file starts with `// Copyright (c) Microsoft Corporation.` |
| 57 | + and `// Licensed under the MIT License.` |
0 commit comments