Skip to content

Commit 8075515

Browse files
rjmholtTylerLeonhardt
authored andcommitted
Add events for PowerShell execution status (running, completed, etc). (#632)
* Add events for PowerShell execution status (running, completed, etc). Create notification events for when the Language Server runs PowerShell scripts, so the client is informed about the status of the running script. * Remove empty <return> doc-comments
1 parent aa893b2 commit 8075515

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol;
2+
3+
namespace Microsoft.PowerShell.EditorServices.Protocol.LanguageServer
4+
{
5+
/// <summary>
6+
/// Defines an event type for PowerShell context execution status changes (e.g. execution has completed)
7+
/// </summary>
8+
public class ExecutionStatusChangedEvent
9+
{
10+
/// <summary>
11+
/// The notification type for execution status change events in the message protocol
12+
/// </summary>
13+
public static readonly
14+
NotificationType<object, object> Type =
15+
NotificationType<object, object>.Create("powerShell/executionStatusChanged");
16+
}
17+
}

src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ public LanguageServer(
5656
{
5757
this.Logger = logger;
5858
this.editorSession = editorSession;
59+
// Attach to the underlying PowerShell context to listen for changes in the runspace or execution status
5960
this.editorSession.PowerShellContext.RunspaceChanged += PowerShellContext_RunspaceChanged;
61+
this.editorSession.PowerShellContext.ExecutionStatusChanged += PowerShellContext_ExecutionStatusChanged;
6062

6163
// Attach to ExtensionService events
6264
this.editorSession.ExtensionService.CommandAdded += ExtensionService_ExtensionAdded;
@@ -1273,6 +1275,18 @@ await this.messageSender.SendEvent(
12731275
new Protocol.LanguageServer.RunspaceDetails(e.NewRunspace));
12741276
}
12751277

1278+
/// <summary>
1279+
/// Event hook on the PowerShell context to listen for changes in script execution status
1280+
/// </summary>
1281+
/// <param name="sender">the PowerShell context sending the execution event</param>
1282+
/// <param name="e">details of the execution status change</param>
1283+
private async void PowerShellContext_ExecutionStatusChanged(object sender, ExecutionStatusChangedEventArgs e)
1284+
{
1285+
await this.messageSender.SendEvent(
1286+
ExecutionStatusChangedEvent.Type,
1287+
e);
1288+
}
1289+
12761290
private async void ExtensionService_ExtensionAdded(object sender, EditorCommand e)
12771291
{
12781292
await this.messageSender.SendEvent(

0 commit comments

Comments
 (0)