Skip to content

Commit 3591ee1

Browse files
SeeminglyScienceTylerLeonhardt
authored andcommitted
Run one invocation per SetBreakpoints request (#1117)
* 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. * Fix usage of preview only syntax
1 parent 8114a9b commit 3591ee1

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

Diff for: src/PowerShellEditorServices/Services/DebugAdapter/DebugService.cs

+20-4
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,24 @@ public async Task<BreakpointDetails[]> SetLineBreakpointsAsync(
189189
await this.ClearBreakpointsInFileAsync(scriptFile);
190190
}
191191

192+
PSCommand psCommand = null;
192193
foreach (BreakpointDetails breakpoint in breakpoints)
193194
{
194-
PSCommand psCommand = new PSCommand();
195-
psCommand.AddCommand(@"Microsoft.PowerShell.Utility\Set-PSBreakpoint");
196-
psCommand.AddParameter("Script", escapedScriptPath);
197-
psCommand.AddParameter("Line", breakpoint.LineNumber);
195+
// On first iteration psCommand will be null, every subsequent
196+
// iteration will need to start a new statement.
197+
if (psCommand == null)
198+
{
199+
psCommand = new PSCommand();
200+
}
201+
else
202+
{
203+
psCommand.AddStatement();
204+
}
205+
206+
psCommand
207+
.AddCommand(@"Microsoft.PowerShell.Utility\Set-PSBreakpoint")
208+
.AddParameter("Script", escapedScriptPath)
209+
.AddParameter("Line", breakpoint.LineNumber);
198210

199211
// Check if the user has specified the column number for the breakpoint.
200212
if (breakpoint.ColumnNumber.HasValue && breakpoint.ColumnNumber.Value > 0)
@@ -222,7 +234,11 @@ public async Task<BreakpointDetails[]> SetLineBreakpointsAsync(
222234

223235
psCommand.AddParameter("Action", actionScriptBlock);
224236
}
237+
}
225238

239+
// If no PSCommand was created then there are no breakpoints to set.
240+
if (psCommand != null)
241+
{
226242
IEnumerable<Breakpoint> configuredBreakpoints =
227243
await this.powerShellContext.ExecuteCommandAsync<Breakpoint>(psCommand);
228244

0 commit comments

Comments
 (0)