PowerShell / PowerShell/PowerShellEditorServices

Hook up PSES events to PSEventManager

Open
#613 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Area-Language Server Issue-Enhancement
Dominant language
C#
Stars
767
Forks
266
Avg merge
3d 16h
Merged PRs (30d)
1

Description

Right now the only way to register event/request handlers is to override them via IMessageHandlers from the component registry. This has a few issues

  1. As far as I can tell this only allows you to override handlers, not add to them. Doing this as part of an extension module would break existing functionality.

  2. These delegates are invoked from a thread that doesn't have a default runspace. This means if the delegate is a converted script block it will fail (and crash PSES)

I propose we add the following:

  1. Function or cmdlet Register-EditorEvent. This should work like Register-EngineEvent. It would take a SourceIdentifier as the event name and script block to register as a PSEventSubscriber. Ideally this would also include argument completion for event names.

  2. A class that holds constants with event names (see PSEngineEvent)

  3. Additional logic to existing handlers and other events to check for relevant event subscribers and if found generate the event.

  4. If the event/handler typically returns a value, a property would need to be added to the EventArgs to handle output (PowerShell eventing doesn't handle delegate output)

This would solve a few issues

  1. Extension modules could register additional handlers the same way in PowerShell and compiled languages

  2. Eventing should take care of all the runspace management and queuing of commands that would normally make this a huge pain. This would also allow the events to be ran in between sequence points of an in progress command.

  3. Allow multiple handlers for a single request/event

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the existing IMessageHandlers in the component registry and comparing the proposed Register-EditorEvent behavior with Register-EngineEvent, PSEventSubscriber, and PSEngineEvent. Define the event-name constants, subscriber registration, handler dispatch, runspace queuing, and EventArgs output behavior; done means multiple PowerShell and compiled-language handlers can coexist without replacing existing handlers.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, powershell
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.