File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed
PowerShellEditorServices.Protocol/Server
PowerShellEditorServices/Debugging Expand file tree Collapse file tree 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(
182182 object shutdownParams ,
183183 RequestContext < InitializeResponseBody > requestContext )
184184 {
185+ // Clear any existing breakpoints before proceeding
186+ await this . ClearSessionBreakpoints ( ) ;
187+
185188 // Now send the Initialize response to continue setup
186189 await requestContext . SendResult (
187190 new InitializeResponseBody {
@@ -420,6 +423,9 @@ await requestContext.SendError(
420423 return ;
421424 }
422425
426+ // Clear any existing breakpoints before proceeding
427+ await this . ClearSessionBreakpoints ( ) ;
428+
423429 // Execute the Debug-Runspace command but don't await it because it
424430 // will block the debug adapter initialization process. The
425431 // InitializedEvent will be sent as soon as the RunspaceChanged
@@ -883,6 +889,18 @@ private void UnregisterEventHandlers()
883889 this . editorSession . PowerShellContext . DebuggerResumed -= this . powerShellContext_DebuggerResumed ;
884890 }
885891
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+
886904 #endregion
887905
888906 #region Event Handlers
Original file line number Diff line number Diff line change @@ -660,6 +660,18 @@ public VariableScope[] GetVariableScopes(int stackFrameId)
660660 } ;
661661 }
662662
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+
663675 #endregion
664676
665677 #region Private Methods
You can’t perform that action at this time.
0 commit comments