Skip to content

Back language model tools and the Command Explorer with new LSP requests#2298

Open
andyleejordan wants to merge 6 commits into
mainfrom
andyleejordan/lm-tools-command-explorer
Open

Back language model tools and the Command Explorer with new LSP requests#2298
andyleejordan wants to merge 6 commits into
mainfrom
andyleejordan/lm-tools-command-explorer

Conversation

@andyleejordan

@andyleejordan andyleejordan commented Jun 9, 2026

Copy link
Copy Markdown
Member

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.

  1. Return help text from the powerShell/showHelp request — convert showHelp from a notification to a request returning ShowHelpResult { HelpText }, capturing Get-Help -Full | Out-String and trimming both ends (it pads a leading and trailing blank line).
  2. Enhance get_command for tools and the Command Explorer — optional Name/Module filters (wildcard, -ErrorAction Ignore), an ExcludeParameters fast path plus ModuleVersion, unconditional exclusion of editor-injected commands (the fake PSConsoleHostReadLine 0.0.0 and VS Code shell-integration helpers), and opt-in ExcludeDefaultFunctions enumerated from InitialSessionState.CreateDefault2().
  3. Add a powerShell/getModule handler — 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.
  4. Add Copilot instructions documenting build and test.

Drafted by Copilot (Claude Opus 4.8) — please review/edit before marking ready.

andyleejordan and others added 4 commits June 9, 2026 15:20
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>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/showHelp from a notification into a request that returns full help text as a string.
  • Enhances powerShell/getCommand with optional name/module filtering, a fast path to exclude parameter metadata, and filtering for editor-injected/default-session commands.
  • Adds a new powerShell/getModule request 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.

Comment on lines +71 to +73
string helpText = results is { Count: > 0 }
? string.Concat(results).Trim()
: string.Empty;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No thanks.

// 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"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed, it's literally only that and injected by us.

Comment on lines +38 to +39
`src/PowerShellEditorServices.Hosting/BuildInfo.cs` is auto-generated by the build script and
git-ignored for changes. Do not edit it manually.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it's pretty much accurate.

Comment on lines +15 to +16
[Serial, Method("powerShell/getModule", Direction.ClientToServer)]
internal interface IGetModuleHandler : IJsonRpcRequestHandler<GetModuleParams, PSModuleMessage> { }

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh sure fine, kicked off an agent.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants