Skip to content

Commit

Permalink
Clear existing breakpoints in session when debugger starts
Browse files Browse the repository at this point in the history
This change ensures that the breakpoints the user has in their runspace
correspond to the list of breakpoints that are enabled in the debug
adapter client.

Resolves PowerShell/vscode-powershell#625
  • Loading branch information
daviwil committed Oct 27, 2017
1 parent c27865a commit 045835d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ private async Task HandleInitializeRequest(
object shutdownParams,
RequestContext<InitializeResponseBody> requestContext)
{
// Clear any existing breakpoints before proceeding
await this.ClearSessionBreakpoints();

// Now send the Initialize response to continue setup
await requestContext.SendResult(
new InitializeResponseBody {
Expand Down Expand Up @@ -420,6 +423,9 @@ await requestContext.SendError(
return;
}

// Clear any existing breakpoints before proceeding
await this.ClearSessionBreakpoints();

// Execute the Debug-Runspace command but don't await it because it
// will block the debug adapter initialization process. The
// InitializedEvent will be sent as soon as the RunspaceChanged
Expand Down Expand Up @@ -883,6 +889,18 @@ private void UnregisterEventHandlers()
this.editorSession.PowerShellContext.DebuggerResumed -= this.powerShellContext_DebuggerResumed;
}

private async Task ClearSessionBreakpoints()
{
try
{
await this.editorSession.DebugService.ClearAllBreakpoints();
}
catch (Exception e)
{
Logger.WriteException("Caught exception while clearing breakpoints from session", e);
}
}

#endregion

#region Event Handlers
Expand Down
12 changes: 12 additions & 0 deletions src/PowerShellEditorServices/Debugging/DebugService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,18 @@ public VariableScope[] GetVariableScopes(int stackFrameId)
};
}

/// <summary>
/// Clears all breakpoints in the current session.
/// </summary>
public async Task ClearAllBreakpoints()
{
PSCommand psCommand = new PSCommand();
psCommand.AddCommand(@"Microsoft.PowerShell.Utility\Get-PSBreakpoint");
psCommand.AddCommand(@"Microsoft.PowerShell.Utility\Remove-PSBreakpoint");

await this.powerShellContext.ExecuteCommand<object>(psCommand);
}

#endregion

#region Private Methods
Expand Down

0 comments on commit 045835d

Please sign in to comment.