Skip to content

Commit bba2d97

Browse files
Update copilot-instructions.md with architecture, conventions, and release process
Add comprehensive guidance for AI agents including build/lint/test commands, extension architecture (SessionManager, LanguageClientConsumer pattern, features), key conventions (ILogger, settings access, TypeScript style), versioning and release process (even/odd minor scheme, updateVersion.ps1), and cross-repo PSES relationship. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 01e8ef8 commit bba2d97

File tree

1 file changed

+120
-0
lines changed

1 file changed

+120
-0
lines changed

.github/copilot-instructions.md

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,123 @@
11
# Copilot Instructions for vscode-powershell
22

3+
## Overview
4+
5+
This is the VS Code extension for PowerShell — it is a Language Server Protocol (LSP) client
6+
that communicates with [PowerShellEditorServices][] (PSES), the LSP server. The extension
7+
manages the lifecycle of the PSES process, provides UI features, and handles debugging.
8+
9+
[PowerShellEditorServices]: https://github.com/PowerShell/PowerShellEditorServices
10+
11+
## Build, Lint, and Test
12+
13+
```sh
14+
npm install --include=optional # Install all deps (lint/test tools are in optionalDependencies)
15+
npm run compile # Build with esbuild (outputs to dist/)
16+
npm run lint # ESLint (strict TypeScript-aware rules)
17+
npm run format # Prettier check (with organize-imports plugin)
18+
npm test # Integration tests via @vscode/test-cli (launches VS Code Insiders)
19+
```
20+
21+
After any code change, always run `npm run compile`, `npm run lint`, and `npm run format` to
22+
catch build errors, lint violations, and formatting issues before committing.
23+
24+
There is no way to run a single test from the command line; the test suite runs inside a VS
25+
Code instance via `@vscode/test-cli` and uses Mocha BDD (`describe`/`it`). Tests live in
26+
`test/` mirroring `src/` structure (`test/core/`, `test/features/`). The test config is in
27+
`.vscode-test.mjs`.
28+
29+
## Architecture
30+
31+
### Extension Activation (`src/extension.ts`)
32+
33+
`activate()` creates the `Logger`, `SessionManager`, and two groups of features:
34+
35+
1. **Standalone features** — registered as commands, don't need the language client (e.g.
36+
`PesterTestsFeature`, `CodeActionsFeature`, `ExamplesFeature`)
37+
2. **LanguageClientConsumers** — features that depend on the LSP client (e.g.
38+
`ConsoleFeature`, `DebugSessionFeature`, `ShowHelpFeature`)
39+
40+
### Session Management (`src/session.ts`)
41+
42+
`SessionManager` owns the full lifecycle: finding a PowerShell executable (`src/platform.ts`),
43+
spawning the PSES process (`src/process.ts` via `PowerShellProcess`), connecting the
44+
`LanguageClient`, and restarting on critical setting changes. It distributes the language
45+
client to all `LanguageClientConsumer` instances.
46+
47+
### LanguageClientConsumer Pattern (`src/languageClientConsumer.ts`)
48+
49+
All features that need the LSP client extend the abstract `LanguageClientConsumer` class. It
50+
provides a shared promise-based mechanism (`getLanguageClient()`) to wait for the client to
51+
start, with a cancellable progress notification. Subclasses override `onLanguageClientSet()`
52+
to register their LSP handlers.
53+
54+
### Feature Modules (`src/features/`)
55+
56+
Each file typically exports one class implementing `vscode.Disposable`. Features register VS
57+
Code commands, event handlers, or LSP request/notification handlers. Custom LSP message types
58+
are defined as `RequestType`/`NotificationType` constants in the same file.
59+
60+
### External API (`src/features/ExternalApi.ts`)
61+
62+
The `IPowerShellExtensionClient` interface is the public API other VS Code extensions use to
63+
interact with this extension (register, wait for start, get version details).
64+
65+
### Bundled Modules (`modules/`)
66+
67+
Contains vendored PowerShell modules (PSES, PSReadLine, PSScriptAnalyzer) that ship with the
68+
extension. For local development, the [PowerShellEditorServices][] repo is cloned as a
69+
sibling directory (`../PowerShellEditorServices`). Changes to LSP messages, server-side
70+
features, or the debugger adapter require work in that repo — this extension is only the
71+
client side. For cross-repo work, use the multi-root workspace
72+
`pwsh-extension-dev.code-workspace` which includes both repositories.
73+
74+
## Key Conventions
75+
76+
- **VS Code extension best practices**: Follow the
77+
[VS Code Extension Guidelines](https://code.visualstudio.com/api/references/extension-guidelines)
78+
and [UX Guidelines](https://code.visualstudio.com/api/ux-guidelines/overview). Use VS Code's
79+
APIs idiomatically (e.g. `vscode.window` for UI, `vscode.workspace` for configuration,
80+
disposable patterns for lifecycle management).
81+
- **Logging**: Use the `ILogger` interface (not `console.log`). The concrete `Logger` class
82+
wraps a VS Code `LogOutputChannel`. Tests use `TestLogger` from `test/utils.ts`.
83+
- **Settings**: Settings are defined in `package.json` under `contributes.configuration` and
84+
read via `vscode.workspace.getConfiguration("powershell")` at point of use. Helper functions
85+
(`changeSetting`, `validateCwdSetting`, `getChosenWorkspace`) live in `src/settings.ts`.
86+
- **TypeScript style**: Strict mode, ESNext target, `verbatimModuleSyntax`. ESLint enforces
87+
`explicit-function-return-type`. Unused vars prefixed with `_`. Formatting via Prettier
88+
with the `organize-imports` plugin.
89+
- **Import style**: Uses TypeScript `import x = require("x")` for Node/VS Code built-ins
90+
alongside ESM-style `import` for other modules.
91+
- **File headers**: Every source file starts with `// Copyright (c) Microsoft Corporation.`
92+
and `// Licensed under the MIT License.`
93+
94+
## Versioning and Release Process
95+
96+
The extension version follows `vYYYY.X.Z` (year, minor, patch) — not semver. Releases are
97+
based on completed work, not a schedule. Key rules:
98+
99+
- **Even minor** = release (e.g. `v2026.2.0`), **odd minor** = pre-release (e.g. `v2026.3.0-preview`)
100+
- A release's version is `n-1` of its preview: release `v2026.2.0` is previewed by `v2026.3.0-preview`
101+
- This ensures the marketplace always shows a pre-release option (odd > even by version sort)
102+
- The `preview` field in `package.json` is **always `false`** — even for pre-releases
103+
- Append `-preview` to the version in the changelog and Git tag, but **not** in `package.json`
104+
(the marketplace ignores pre-release suffixes)
105+
- For multiple pre-releases, increment patch: `v2026.3.0-preview`, `v2026.3.1-preview`, etc.
106+
- PSES version must **not** change between a pre-release and its subsequent release
107+
108+
### Release Steps
109+
110+
1. Use `./tools/updateVersion.ps1 -Version "<version>" -Changes "<summary>"` in both repos
111+
(PSES first, then vscode-powershell). The script validates even/odd rules, updates
112+
`package.json` version, prepends a changelog entry (auto-including the PSES version from
113+
`../PowerShellEditorServices`), and creates a commit.
114+
2. Push to an ephemeral `release` branch, open and merge a PR to `main`.
115+
3. After merge, push `main` to the Azure DevOps remote (`ado`) to trigger signing pipelines.
116+
4. Download and test assets from draft GitHub Releases, then publish.
117+
118+
PowerShellEditorServices uses standard semver (`vX.Y.Z`). Git tags (`vX.Y.Z`) mark releases;
119+
the `release` branch is ephemeral and deleted after each release.
120+
3121
## Updating NPM Packages
4122

5123
- Read [docs/development.md](../docs/development.md) "Tracking Upstream Dependencies" first
@@ -11,3 +129,5 @@
11129
- Fix any new lint warnings from updates to ESLint
12130
- Use `npm audit` to identify vulnerabilities
13131
- Do not use `npm audit fix --force` when a vulnerability is in a transitive dependency, instead add an `overrides` entry
132+
- When `engines.vscode` is updated, `@types/vscode` must match (using `~` not `^`), and
133+
`@types/node` major must match the Node.js version in VS Code's Electron

0 commit comments

Comments
 (0)