public async Task RemoveBreakpointsAsync(IEnumerable <Breakpoint> breakpoints) { if (BreakpointApiUtils.SupportsBreakpointApis) { foreach (Breakpoint breakpoint in breakpoints) { BreakpointApiUtils.RemoveBreakpoint( _powerShellContextService.CurrentRunspace.Runspace.Debugger, breakpoint, _debugStateService.RunspaceId); switch (breakpoint) { case CommandBreakpoint commandBreakpoint: CommandBreakpoints.Remove(commandBreakpoint); break; case LineBreakpoint lineBreakpoint: if (BreakpointsPerFile.TryGetValue(lineBreakpoint.Script, out HashSet <Breakpoint> bps)) { bps.Remove(lineBreakpoint); } break; default: throw new ArgumentException("Unsupported breakpoint type."); } } return; } // Legacy behavior var breakpointIds = breakpoints.Select(b => b.Id).ToArray(); if (breakpointIds.Length > 0) { PSCommand psCommand = new PSCommand(); psCommand.AddCommand(@"Microsoft.PowerShell.Utility\Remove-PSBreakpoint"); psCommand.AddParameter("Id", breakpoints.Select(b => b.Id).ToArray()); await _powerShellContextService.ExecuteCommandAsync <object>(psCommand); } }
/// <summary> /// Clears all breakpoints in the current session. /// </summary> public async Task RemoveAllBreakpointsAsync(string scriptPath = null) { try { if (BreakpointApiUtils.SupportsBreakpointApis) { foreach (Breakpoint breakpoint in BreakpointApiUtils.GetBreakpoints( _powerShellContextService.CurrentRunspace.Runspace.Debugger, _debugStateService.RunspaceId)) { if (scriptPath == null || scriptPath == breakpoint.Script) { BreakpointApiUtils.RemoveBreakpoint( _powerShellContextService.CurrentRunspace.Runspace.Debugger, breakpoint, _debugStateService.RunspaceId); } } return; } // Legacy behavior PSCommand psCommand = new PSCommand(); psCommand.AddCommand(@"Microsoft.PowerShell.Utility\Get-PSBreakpoint"); if (!string.IsNullOrEmpty(scriptPath)) { psCommand.AddParameter("Script", scriptPath); } psCommand.AddCommand(@"Microsoft.PowerShell.Utility\Remove-PSBreakpoint"); await _powerShellContextService.ExecuteCommandAsync <object>(psCommand).ConfigureAwait(false); } catch (Exception e) { _logger.LogException("Caught exception while clearing breakpoints from session", e); } }