|
| 1 | +# Copilot Instructions for PowerShell Editor Services |
| 2 | + |
| 3 | +## Build & Test |
| 4 | + |
| 5 | +Requires .NET SDK 8.0+. Use `dotnet` directly for building and testing — it's faster and |
| 6 | +requires no extra tooling. The `Invoke-Build` script requires the `InvokeBuild` and `platyPS` |
| 7 | +PowerShell modules (platyPS is `#Requires`'d at the top, so the whole script fails without it), |
| 8 | +and is mainly needed to assemble the full PowerShell module for release. |
| 9 | + |
| 10 | +```powershell |
| 11 | +# Build (run both; Hosting depends on the core library) |
| 12 | +dotnet publish src/PowerShellEditorServices/PowerShellEditorServices.csproj -f netstandard2.0 |
| 13 | +dotnet publish src/PowerShellEditorServices.Hosting/PowerShellEditorServices.Hosting.csproj -f net8.0 |
| 14 | +
|
| 15 | +# Run all unit tests |
| 16 | +dotnet test test/PowerShellEditorServices.Test/ --framework net8.0 |
| 17 | +
|
| 18 | +# Run a single test by name |
| 19 | +dotnet test test/PowerShellEditorServices.Test/ --framework net8.0 --filter "FullyQualifiedName~CompletesCommandInFile" |
| 20 | +
|
| 21 | +# Run tests by trait category |
| 22 | +dotnet test test/PowerShellEditorServices.Test/ --framework net8.0 --filter "Category=Completions" |
| 23 | +
|
| 24 | +# Run E2E tests |
| 25 | +dotnet test test/PowerShellEditorServices.Test.E2E/ --framework net8.0 |
| 26 | +``` |
| 27 | + |
| 28 | +For assembling the full module or running the complete CI suite (including Windows PowerShell |
| 29 | +5.1 targets), use `Invoke-Build` with the `InvokeBuild` and `platyPS` modules installed: |
| 30 | + |
| 31 | +```powershell |
| 32 | +Invoke-Build Build # full build + module assembly + help generation |
| 33 | +Invoke-Build TestPS74 # unit tests via build script |
| 34 | +Invoke-Build TestE2EPwsh # E2E tests via build script |
| 35 | +Invoke-Build Build -Configuration Release # required before PRs (enforces XML doc comments) |
| 36 | +``` |
| 37 | + |
| 38 | +`src/PowerShellEditorServices.Hosting/BuildInfo.cs` is auto-generated by the build script and |
| 39 | +git-ignored for changes. Do not edit it manually. |
| 40 | + |
| 41 | +## Architecture |
| 42 | + |
| 43 | +PowerShell Editor Services (PSES) is a **Language Server Protocol (LSP)** and **Debug Adapter |
| 44 | +Protocol (DAP)** server for PowerShell, consumed by VS Code and other editors. |
| 45 | + |
| 46 | +### Projects |
| 47 | + |
| 48 | +- **`src/PowerShellEditorServices`** (`netstandard2.0`) — Core library containing all LSP/DAP |
| 49 | + handlers, services, and the PowerShell execution engine. Namespace: |
| 50 | + `Microsoft.PowerShell.EditorServices`. |
| 51 | +- **`src/PowerShellEditorServices.Hosting`** (`net8.0`, `net462`) — Entry point layer that loads |
| 52 | + PSES into a PowerShell process via `StartEditorServicesCommand`. Uses a custom |
| 53 | + `AssemblyLoadContext` (`PsesLoadContext`) on .NET Core to isolate dependencies. |
| 54 | +- **`module/PowerShellEditorServices/`** — The shipped PowerShell module. The build assembles |
| 55 | + compiled binaries into `bin/Core/` (net8.0) and `bin/Desktop/` (net462). The module manifest |
| 56 | + loads the appropriate DLL based on PowerShell edition. |
| 57 | + |
| 58 | +### Key Services (registered in `PsesServiceCollectionExtensions`) |
| 59 | + |
| 60 | +- **`PsesInternalHost`** — The central PowerShell execution host. Also implements |
| 61 | + `IRunspaceContext` and `IInternalPowerShellExecutionService`. |
| 62 | +- **`WorkspaceService`** — Manages open documents and workspace files. |
| 63 | +- **`SymbolsService`** — Provides symbol navigation (go-to-definition, find references). |
| 64 | +- **`AnalysisService`** — Integrates PSScriptAnalyzer for real-time diagnostics. |
| 65 | +- **`ConfigurationService`** — Manages editor/client settings. |
| 66 | +- **`ExtensionService`** — Supports the `$psEditor` API for editor extensions. |
| 67 | + |
| 68 | +### LSP/DAP Handler Pattern |
| 69 | + |
| 70 | +Handlers live under `Services/<Feature>/Handlers/` and follow a consistent pattern: |
| 71 | + |
| 72 | +- Class name: `Pses<Feature>Handler`, marked `internal` |
| 73 | +- Inherits from an OmniSharp base class (e.g., `CompletionHandlerBase`, `HoverHandlerBase`) |
| 74 | +- Dependencies injected via constructor (`ILoggerFactory`, services) |
| 75 | +- Overrides `CreateRegistrationOptions()` and `Handle()` |
| 76 | +- Uses `LspUtils.PowerShellDocumentSelector` for document registration |
| 77 | + |
| 78 | +### Server Setup |
| 79 | + |
| 80 | +- `PsesLanguageServer` — Configures and runs the LSP server using OmniSharp |
| 81 | +- `PsesDebugServer` — Configures and runs the DAP server |
| 82 | +- Both use `Microsoft.Extensions.DependencyInjection` for service registration |
| 83 | + |
| 84 | +## Conventions |
| 85 | + |
| 86 | +### C# Style |
| 87 | + |
| 88 | +- All files require the copyright header: `// Copyright (c) Microsoft Corporation.` / |
| 89 | + `// Licensed under the MIT License.` |
| 90 | +- `.editorconfig` enforces many rules as **errors**, including unused variables, async/threading |
| 91 | + rules (`VSTHRD*`), and modern C# idioms (pattern matching, null checks, expression bodies). |
| 92 | +- Roslynator analyzers are enabled for formatting and code quality. |
| 93 | +- Use `Microsoft.Extensions.Logging` (`ILogger<T>` via `ILoggerFactory`) for all logging. |
| 94 | + |
| 95 | +### Testing |
| 96 | + |
| 97 | +- **Framework:** xUnit with `Xunit.SkippableFact` for conditionally skipped tests. |
| 98 | +- **Host setup:** Use `PsesHostFactory.Create(loggerFactory)` to get an isolated |
| 99 | + `PsesInternalHost` for testing. Tests implement `IAsyncLifetime` for async setup/teardown. |
| 100 | +- **Traits:** Tests use `[Trait("Category", "...")]` for filtering (e.g., `"Completions"`, |
| 101 | + `"Symbols"`). |
| 102 | +- **Fixtures:** Test PowerShell scripts live in `test/PowerShellEditorServices.Test/Fixtures/`. |
| 103 | +- **E2E tests** are in a separate project (`PowerShellEditorServices.Test.E2E`) and test the |
| 104 | + full LSP client-server interaction. |
| 105 | + |
| 106 | +### Multi-targeting |
| 107 | + |
| 108 | +The core library targets `netstandard2.0` for compatibility with both .NET Core and .NET |
| 109 | +Framework. The hosting project and tests dual-target `net8.0` and `net462` (Windows PowerShell |
| 110 | +5.1). Non-Windows platforms skip `net462` targets. |
0 commit comments