File tree 2 files changed +30
-0
lines changed
PowerShellEditorServices/Debugging
PowerShellEditorServices.Protocol/Server
2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -182,6 +182,9 @@ private async Task HandleInitializeRequest(
182
182
object shutdownParams ,
183
183
RequestContext < InitializeResponseBody > requestContext )
184
184
{
185
+ // Clear any existing breakpoints before proceeding
186
+ await this . ClearSessionBreakpoints ( ) ;
187
+
185
188
// Now send the Initialize response to continue setup
186
189
await requestContext . SendResult (
187
190
new InitializeResponseBody {
@@ -420,6 +423,9 @@ await requestContext.SendError(
420
423
return ;
421
424
}
422
425
426
+ // Clear any existing breakpoints before proceeding
427
+ await this . ClearSessionBreakpoints ( ) ;
428
+
423
429
// Execute the Debug-Runspace command but don't await it because it
424
430
// will block the debug adapter initialization process. The
425
431
// InitializedEvent will be sent as soon as the RunspaceChanged
@@ -883,6 +889,18 @@ private void UnregisterEventHandlers()
883
889
this . editorSession . PowerShellContext . DebuggerResumed -= this . powerShellContext_DebuggerResumed ;
884
890
}
885
891
892
+ private async Task ClearSessionBreakpoints ( )
893
+ {
894
+ try
895
+ {
896
+ await this . editorSession . DebugService . ClearAllBreakpoints ( ) ;
897
+ }
898
+ catch ( Exception e )
899
+ {
900
+ Logger . WriteException ( "Caught exception while clearing breakpoints from session" , e ) ;
901
+ }
902
+ }
903
+
886
904
#endregion
887
905
888
906
#region Event Handlers
Original file line number Diff line number Diff line change @@ -660,6 +660,18 @@ public VariableScope[] GetVariableScopes(int stackFrameId)
660
660
} ;
661
661
}
662
662
663
+ /// <summary>
664
+ /// Clears all breakpoints in the current session.
665
+ /// </summary>
666
+ public async Task ClearAllBreakpoints ( )
667
+ {
668
+ PSCommand psCommand = new PSCommand ( ) ;
669
+ psCommand . AddCommand ( @"Microsoft.PowerShell.Utility\Get-PSBreakpoint" ) ;
670
+ psCommand . AddCommand ( @"Microsoft.PowerShell.Utility\Remove-PSBreakpoint" ) ;
671
+
672
+ await this . powerShellContext . ExecuteCommand < object > ( psCommand ) ;
673
+ }
674
+
663
675
#endregion
664
676
665
677
#region Private Methods
You can’t perform that action at this time.
0 commit comments