Skip to content

Commit 23304a2

Browse files
fallback get-psbreakpoint
1 parent 4d33882 commit 23304a2

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

src/PowerShellEditorServices/Services/DebugAdapter/BreakpointService.cs

+21-5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System;
77
using System.Collections.Concurrent;
88
using System.Collections.Generic;
9+
using System.Collections.ObjectModel;
910
using System.Linq;
1011
using System.Management.Automation;
1112
using System.Management.Automation.Language;
@@ -41,11 +42,20 @@ public BreakpointService(
4142
_debugStateService = debugStateService;
4243
}
4344

44-
public List<Breakpoint> GetBreakpoints()
45+
public async Task<List<Breakpoint>> GetBreakpointsAsync()
4546
{
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();
4959
}
5060

5161
public async Task<IEnumerable<BreakpointDetails>> SetBreakpointsAsync(string escapedScriptPath, IEnumerable<BreakpointDetails> breakpoints)
@@ -238,9 +248,15 @@ public async Task RemoveAllBreakpointsAsync(string scriptPath = null)
238248

239249
PSCommand psCommand = new PSCommand();
240250
psCommand.AddCommand(@"Microsoft.PowerShell.Utility\Get-PSBreakpoint");
251+
252+
if (!string.IsNullOrEmpty(scriptPath))
253+
{
254+
psCommand.AddParameter("Script", scriptPath);
255+
}
256+
241257
psCommand.AddCommand(@"Microsoft.PowerShell.Utility\Remove-PSBreakpoint");
242258

243-
await _powerShellContextService.ExecuteCommandAsync<object>(psCommand);
259+
await _powerShellContextService.ExecuteCommandAsync<object>(psCommand).ConfigureAwait(false);
244260
}
245261
catch (Exception e)
246262
{

src/PowerShellEditorServices/Services/DebugAdapter/DebugService.cs

+4-3
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public async Task<CommandBreakpointDetails[]> SetCommandBreakpointsAsync(
212212
if (clearExisting)
213213
{
214214
// Flatten dictionary values into one list and remove them all.
215-
await _breakpointService.RemoveBreakpointsAsync(_breakpointService.GetBreakpoints().Where( i => i is CommandBreakpoint)).ConfigureAwait(false);
215+
await _breakpointService.RemoveBreakpointsAsync((await _breakpointService.GetBreakpointsAsync()).Where( i => i is CommandBreakpoint)).ConfigureAwait(false);
216216
}
217217

218218
if (breakpoints.Length > 0)
@@ -672,8 +672,9 @@ private async Task ClearBreakpointsInFileAsync(ScriptFile scriptFile)
672672
// {
673673
// if (breakpoints.Count > 0)
674674
// {
675-
await _breakpointService.RemoveBreakpointsAsync(_breakpointService.GetBreakpoints()
676-
.Where(bp => bp is LineBreakpoint lbp && string.Equals(lbp.Script, scriptFile.FilePath))).ConfigureAwait(false);
675+
await _breakpointService.RemoveAllBreakpointsAsync(scriptFile.FilePath).ConfigureAwait(false);
676+
// await _breakpointService.RemoveBreakpointsAsync((await _breakpointService.GetBreakpointsAsync())
677+
// .Where(bp => bp is LineBreakpoint lbp && string.Equals(lbp.Script, scriptFile.FilePath))).ConfigureAwait(false);
677678

678679
// Clear the existing breakpoints list for the file
679680
// breakpoints.Clear();

0 commit comments

Comments
 (0)