diff --git a/src/PowerShellEditorServices/Services/DebugAdapter/DebugService.cs b/src/PowerShellEditorServices/Services/DebugAdapter/DebugService.cs index dbde29254..66e106730 100644 --- a/src/PowerShellEditorServices/Services/DebugAdapter/DebugService.cs +++ b/src/PowerShellEditorServices/Services/DebugAdapter/DebugService.cs @@ -189,12 +189,24 @@ public async Task SetLineBreakpointsAsync( await this.ClearBreakpointsInFileAsync(scriptFile); } + PSCommand psCommand = null; foreach (BreakpointDetails breakpoint in breakpoints) { - PSCommand psCommand = new PSCommand(); - psCommand.AddCommand(@"Microsoft.PowerShell.Utility\Set-PSBreakpoint"); - psCommand.AddParameter("Script", escapedScriptPath); - psCommand.AddParameter("Line", breakpoint.LineNumber); + // On first iteration psCommand will be null, every subsequent + // iteration will need to start a new statement. + if (psCommand == null) + { + psCommand = new PSCommand(); + } + else + { + psCommand.AddStatement(); + } + + psCommand + .AddCommand(@"Microsoft.PowerShell.Utility\Set-PSBreakpoint") + .AddParameter("Script", escapedScriptPath) + .AddParameter("Line", breakpoint.LineNumber); // Check if the user has specified the column number for the breakpoint. if (breakpoint.ColumnNumber.HasValue && breakpoint.ColumnNumber.Value > 0) @@ -222,7 +234,11 @@ public async Task SetLineBreakpointsAsync( psCommand.AddParameter("Action", actionScriptBlock); } + } + // If no PSCommand was created then there are no breakpoints to set. + if (psCommand != null) + { IEnumerable configuredBreakpoints = await this.powerShellContext.ExecuteCommandAsync(psCommand);