Back language model tools and the Command Explorer with new LSP requests#2298
Back language model tools and the Command Explorer with new LSP requests#2298andyleejordan wants to merge 6 commits into
Conversation
Convert `powerShell/showHelp` from a fire-and-forget notification into a
request that returns `ShowHelpResult { HelpText }`, so the client can render
help in a read-only editor pane (and the language model `get_help` tool can
reuse the same path) instead of printing into the integrated console.
The handler captures `Get-Help -Full | Out-String` and `.Trim()`s both ends —
`Out-String` pads the output with a leading and trailing blank line, which
looked wrong in the help pane and in tool output.
Drafted by Copilot (Claude Opus 4.8).
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The handler previously serialized the entire command table (names, modules, and full parameter metadata) on every request, which is slow enough to hang the `get_command` language model tool and made the Command Explorer take minutes to populate. Extend `GetCommandParams` so callers can ask for only what they need: - `Name`/`Module` (both wildcard-capable) scope the `Get-Command` call so we don't materialize everything; an unmatched filter writes a non-terminating error, so we pass `-ErrorAction Ignore` and return an empty list instead. - `ExcludeParameters` takes a fast path that returns just name, module, and the new `ModuleVersion` without touching `Parameters`/`ParameterSets`, whose resolution and serialization dominate the cost. - Editor-injected commands are always skipped: the PSES host's fake `PSConsoleHostReadLine` (version 0.0.0) and VS Code's shell-integration helpers (`__VSCode-Escape-Value`, `Set-MappedKeyHandler[s]`) are plumbing, not commands a user authored or imported. - `ExcludeDefaultFunctions` (opt-in) drops PowerShell's module-less default-session functions (`cd..`, `prompt`, `TabExpansion2`, ...) and the install's `pwsh.profile.resource` script. The names come from `InitialSessionState.CreateDefault2()` so the list stays correct across PowerShell versions; module-provided commands are never affected. Drafted by Copilot (Claude Opus 4.8). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The Command Explorer groups commands under versioned module nodes and shows a tooltip on hover. Add a `getModule` request that returns a single module's metadata (version, description, path, author, company, project URI, required PowerShell version) so the client can populate those tooltips lazily, and register the handler in `PsesLanguageServer`. Drafted by Copilot (Claude Opus 4.8). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Capture how to build and test the project with `dotnet` directly (faster, no extra modules) versus `Invoke-Build` (needed for assembling the full module and the complete CI suite), so future Copilot sessions don't have to rediscover it. Drafted by Copilot (Claude Opus 4.8). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR adds server-side LSP request support needed by upcoming VS Code extension features (language model tools, redesigned Command Explorer, and a read-only Show Help pane), aligning PowerShellEditorServices with new client capabilities in the companion VS Code PR.
Changes:
- Converts
powerShell/showHelpfrom a notification into a request that returns full help text as a string. - Enhances
powerShell/getCommandwith optional name/module filtering, a fast path to exclude parameter metadata, and filtering for editor-injected/default-session commands. - Adds a new
powerShell/getModulerequest handler plus Copilot build/test instructions documentation.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/PowerShellEditorServices/Services/PowerShell/Handlers/ShowHelpHandler.cs | Switches showHelp to a request and returns trimmed help text from Get-Help -Full | Out-String. |
| src/PowerShellEditorServices/Services/PowerShell/Handlers/GetModuleHandler.cs | Adds a new LSP request to retrieve module metadata for Command Explorer tooltips. |
| src/PowerShellEditorServices/Services/PowerShell/Handlers/GetCommandHandler.cs | Adds filtering/fast-path options and excludes editor-injected/default-session commands. |
| src/PowerShellEditorServices/Server/PsesLanguageServer.cs | Registers the new GetModuleHandler with the language server. |
| .github/copilot-instructions.md | Documents local build/test workflows and repo architecture/conventions for Copilot. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| string helpText = results is { Count: > 0 } | ||
| ? string.Concat(results).Trim() | ||
| : string.Empty; |
| // defines for terminal shell integration (see PsesInternalHost.cs) has | ||
| // no real version, whereas the genuine PSReadLine export always reports | ||
| // a real version, so that export is never matched here. | ||
| if (command.Name == "PSConsoleHostReadLine" |
There was a problem hiding this comment.
Not needed, it's literally only that and injected by us.
| `src/PowerShellEditorServices.Hosting/BuildInfo.cs` is auto-generated by the build script and | ||
| git-ignored for changes. Do not edit it manually. |
There was a problem hiding this comment.
No it's pretty much accurate.
| [Serial, Method("powerShell/getModule", Direction.ClientToServer)] | ||
| internal interface IGetModuleHandler : IJsonRpcRequestHandler<GetModuleParams, PSModuleMessage> { } |
There was a problem hiding this comment.
Ahh sure fine, kicked off an agent.
There was a problem hiding this comment.
Added two E2E tests for powerShell/getModule in the vein of the existing custom-request tests: one asserting metadata is returned for an existing module (Microsoft.PowerShell.Management, including non-empty version) and one asserting a null result for a missing module. Commit b2dbcb7.
Server-side support for new VS Code extension features (language model tools, a redesigned Command Explorer, and a read-only Show Help pane). The client work lives in PowerShell/vscode-powershell#5508 and depends on this PR; the two should be reviewed and merged together.
powerShell/showHelprequest — convertshowHelpfrom a notification to a request returningShowHelpResult { HelpText }, capturingGet-Help -Full | Out-Stringand trimming both ends (it pads a leading and trailing blank line).get_commandfor tools and the Command Explorer — optionalName/Modulefilters (wildcard,-ErrorAction Ignore), anExcludeParametersfast path plusModuleVersion, unconditional exclusion of editor-injected commands (the fakePSConsoleHostReadLine0.0.0 and VS Code shell-integration helpers), and opt-inExcludeDefaultFunctionsenumerated fromInitialSessionState.CreateDefault2().powerShell/getModulehandler — returns a single module's metadata for the Command Explorer's hover tooltips. Covered by E2E tests verifying metadata is returned for an existing module and a null result for a missing module.Drafted by Copilot (Claude Opus 4.8) — please review/edit before marking ready.