Skip to content

Commit 5beeba1

Browse files
committed
Add BreakpointEvent to be sent when breakpoints change in session
This change adds the BreakpointEvent message type to the debug adapter and wires it up to be sent anytime breakpoints change in the editing session. This allows the user to call Set-PSBreakpoint in the integrated console to add new breakpoints and then see them be set in the editor UI. Resolves PowerShell/vscode-powershell#660
1 parent 24d86cf commit 5beeba1

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
// Copyright (c) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
4+
//
5+
6+
using Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol;
7+
8+
namespace Microsoft.PowerShell.EditorServices.Protocol.DebugAdapter
9+
{
10+
public class BreakpointEvent
11+
{
12+
public static readonly
13+
EventType<BreakpointEvent> Type =
14+
EventType<BreakpointEvent>.Create("breakpoint");
15+
16+
public string Reason { get; set; }
17+
18+
public Breakpoint Breakpoint { get; set; }
19+
}
20+
}

src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs

+24
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,7 @@ await this.SendEvent(
842842
private void RegisterEventHandlers()
843843
{
844844
this.editorSession.PowerShellContext.RunspaceChanged += this.powerShellContext_RunspaceChanged;
845+
this.editorSession.DebugService.BreakpointUpdated += DebugService_BreakpointUpdated;
845846
this.editorSession.DebugService.DebuggerStopped += this.DebugService_DebuggerStopped;
846847
this.editorSession.PowerShellContext.DebuggerResumed += this.powerShellContext_DebuggerResumed;
847848

@@ -855,6 +856,7 @@ private void RegisterEventHandlers()
855856
private void UnregisterEventHandlers()
856857
{
857858
this.editorSession.PowerShellContext.RunspaceChanged -= this.powerShellContext_RunspaceChanged;
859+
this.editorSession.DebugService.BreakpointUpdated -= DebugService_BreakpointUpdated;
858860
this.editorSession.DebugService.DebuggerStopped -= this.DebugService_DebuggerStopped;
859861
this.editorSession.PowerShellContext.DebuggerResumed -= this.powerShellContext_DebuggerResumed;
860862

@@ -947,6 +949,28 @@ await this.SendEvent(
947949
});
948950
}
949951

952+
private async void DebugService_BreakpointUpdated(object sender, BreakpointUpdatedEventArgs e)
953+
{
954+
string reason =
955+
e.UpdateType == BreakpointUpdateType.Set
956+
? "new" : "changed";
957+
958+
var breakpoint = Protocol.DebugAdapter.Breakpoint.Create(
959+
BreakpointDetails.Create(e.Breakpoint));
960+
961+
breakpoint.Verified =
962+
!(e.UpdateType == BreakpointUpdateType.Removed ||
963+
e.UpdateType == BreakpointUpdateType.Disabled);
964+
965+
await this.SendEvent(
966+
BreakpointEvent.Type,
967+
new BreakpointEvent
968+
{
969+
Reason = reason,
970+
Breakpoint = breakpoint
971+
});
972+
}
973+
950974
#endregion
951975
}
952976
}

0 commit comments

Comments
 (0)