Skip to content

Commit

Permalink
Add BreakpointEvent to be sent when breakpoints change in session
Browse files Browse the repository at this point in the history
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
  • Loading branch information
daviwil committed Apr 7, 2017
1 parent 24d86cf commit 5beeba1
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//

using Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol;

namespace Microsoft.PowerShell.EditorServices.Protocol.DebugAdapter
{
public class BreakpointEvent
{
public static readonly
EventType<BreakpointEvent> Type =
EventType<BreakpointEvent>.Create("breakpoint");

public string Reason { get; set; }

public Breakpoint Breakpoint { get; set; }
}
}
24 changes: 24 additions & 0 deletions src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,7 @@ await this.SendEvent(
private void RegisterEventHandlers()
{
this.editorSession.PowerShellContext.RunspaceChanged += this.powerShellContext_RunspaceChanged;
this.editorSession.DebugService.BreakpointUpdated += DebugService_BreakpointUpdated;
this.editorSession.DebugService.DebuggerStopped += this.DebugService_DebuggerStopped;
this.editorSession.PowerShellContext.DebuggerResumed += this.powerShellContext_DebuggerResumed;

Expand All @@ -855,6 +856,7 @@ private void RegisterEventHandlers()
private void UnregisterEventHandlers()
{
this.editorSession.PowerShellContext.RunspaceChanged -= this.powerShellContext_RunspaceChanged;
this.editorSession.DebugService.BreakpointUpdated -= DebugService_BreakpointUpdated;
this.editorSession.DebugService.DebuggerStopped -= this.DebugService_DebuggerStopped;
this.editorSession.PowerShellContext.DebuggerResumed -= this.powerShellContext_DebuggerResumed;

Expand Down Expand Up @@ -947,6 +949,28 @@ await this.SendEvent(
});
}

private async void DebugService_BreakpointUpdated(object sender, BreakpointUpdatedEventArgs e)
{
string reason =
e.UpdateType == BreakpointUpdateType.Set
? "new" : "changed";

var breakpoint = Protocol.DebugAdapter.Breakpoint.Create(
BreakpointDetails.Create(e.Breakpoint));

breakpoint.Verified =
!(e.UpdateType == BreakpointUpdateType.Removed ||
e.UpdateType == BreakpointUpdateType.Disabled);

await this.SendEvent(
BreakpointEvent.Type,
new BreakpointEvent
{
Reason = reason,
Breakpoint = breakpoint
});
}

#endregion
}
}

0 comments on commit 5beeba1

Please sign in to comment.