|
6 | 6 | using System;
|
7 | 7 | using System.Collections.Concurrent;
|
8 | 8 | using System.Collections.Generic;
|
| 9 | +using System.Collections.ObjectModel; |
9 | 10 | using System.Linq;
|
10 | 11 | using System.Management.Automation;
|
11 | 12 | using System.Management.Automation.Language;
|
@@ -41,11 +42,20 @@ public BreakpointService(
|
41 | 42 | _debugStateService = debugStateService;
|
42 | 43 | }
|
43 | 44 |
|
44 |
| - public List<Breakpoint> GetBreakpoints() |
| 45 | + public async Task<List<Breakpoint>> GetBreakpointsAsync() |
45 | 46 | {
|
46 |
| - return BreakpointApiUtils.GetBreakpoints( |
47 |
| - _powerShellContextService.CurrentRunspace.Runspace.Debugger, |
48 |
| - _debugStateService.RunspaceId); |
| 47 | + if (VersionUtils.IsPS7OrGreater) |
| 48 | + { |
| 49 | + return BreakpointApiUtils.GetBreakpoints( |
| 50 | + _powerShellContextService.CurrentRunspace.Runspace.Debugger, |
| 51 | + _debugStateService.RunspaceId); |
| 52 | + } |
| 53 | + |
| 54 | + // Legacy behavior |
| 55 | + PSCommand psCommand = new PSCommand(); |
| 56 | + psCommand.AddCommand(@"Microsoft.PowerShell.Utility\Get-PSBreakpoint"); |
| 57 | + IEnumerable<Breakpoint> breakpoints = await _powerShellContextService.ExecuteCommandAsync<Breakpoint>(psCommand); |
| 58 | + return breakpoints.ToList(); |
49 | 59 | }
|
50 | 60 |
|
51 | 61 | public async Task<IEnumerable<BreakpointDetails>> SetBreakpointsAsync(string escapedScriptPath, IEnumerable<BreakpointDetails> breakpoints)
|
@@ -238,9 +248,15 @@ public async Task RemoveAllBreakpointsAsync(string scriptPath = null)
|
238 | 248 |
|
239 | 249 | PSCommand psCommand = new PSCommand();
|
240 | 250 | psCommand.AddCommand(@"Microsoft.PowerShell.Utility\Get-PSBreakpoint");
|
| 251 | + |
| 252 | + if (!string.IsNullOrEmpty(scriptPath)) |
| 253 | + { |
| 254 | + psCommand.AddParameter("Script", scriptPath); |
| 255 | + } |
| 256 | + |
241 | 257 | psCommand.AddCommand(@"Microsoft.PowerShell.Utility\Remove-PSBreakpoint");
|
242 | 258 |
|
243 |
| - await _powerShellContextService.ExecuteCommandAsync<object>(psCommand); |
| 259 | + await _powerShellContextService.ExecuteCommandAsync<object>(psCommand).ConfigureAwait(false); |
244 | 260 | }
|
245 | 261 | catch (Exception e)
|
246 | 262 | {
|
|
0 commit comments