-
Notifications
You must be signed in to change notification settings - Fork 240
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
-
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.
-
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:
-
Function or cmdlet
Register-EditorEvent. This should work likeRegister-EngineEvent. It would take aSourceIdentifieras the event name and script block to register as aPSEventSubscriber. Ideally this would also include argument completion for event names. -
A class that holds constants with event names (see
PSEngineEvent) -
Additional logic to existing handlers and other events to check for relevant event subscribers and if found generate the event.
-
If the event/handler typically returns a value, a property would need to be added to the
EventArgsto handle output (PowerShell eventing doesn't handle delegate output)
This would solve a few issues
-
Extension modules could register additional handlers the same way in PowerShell and compiled languages
-
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.
-
Allow multiple handlers for a single request/event