From 1ab7664c84800ee1515869ee53b16a354812cd9f Mon Sep 17 00:00:00 2001 From: Patrick Meinecke Date: Mon, 25 Nov 2019 22:03:23 -0500 Subject: [PATCH 1/2] Run one invocation per SetBreakpoints request Previously for every SetBreakpoints request we would invoke ExecuteCommandAsync once for every single breakpoint. This change reduces that to a single call per request. --- .../Services/DebugAdapter/DebugService.cs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/PowerShellEditorServices/Services/DebugAdapter/DebugService.cs b/src/PowerShellEditorServices/Services/DebugAdapter/DebugService.cs index dbde29254..b2ae42d46 100644 --- a/src/PowerShellEditorServices/Services/DebugAdapter/DebugService.cs +++ b/src/PowerShellEditorServices/Services/DebugAdapter/DebugService.cs @@ -189,12 +189,16 @@ 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. + psCommand?.AddStatement(); + (psCommand ??= new 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 +226,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); From 5b2459bb0e9422a5fdec807d0fb4a0326d775a22 Mon Sep 17 00:00:00 2001 From: Patrick Meinecke Date: Mon, 25 Nov 2019 22:19:14 -0500 Subject: [PATCH 2/2] Fix usage of preview only syntax --- .../Services/DebugAdapter/DebugService.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/PowerShellEditorServices/Services/DebugAdapter/DebugService.cs b/src/PowerShellEditorServices/Services/DebugAdapter/DebugService.cs index b2ae42d46..66e106730 100644 --- a/src/PowerShellEditorServices/Services/DebugAdapter/DebugService.cs +++ b/src/PowerShellEditorServices/Services/DebugAdapter/DebugService.cs @@ -194,8 +194,16 @@ public async Task SetLineBreakpointsAsync( { // On first iteration psCommand will be null, every subsequent // iteration will need to start a new statement. - psCommand?.AddStatement(); - (psCommand ??= new PSCommand()) + if (psCommand == null) + { + psCommand = new PSCommand(); + } + else + { + psCommand.AddStatement(); + } + + psCommand .AddCommand(@"Microsoft.PowerShell.Utility\Set-PSBreakpoint") .AddParameter("Script", escapedScriptPath) .AddParameter("Line", breakpoint.LineNumber);