Skip to content

Commit

Permalink
fallback get-psbreakpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerLeonhardt committed Jan 29, 2020
1 parent 4d33882 commit 23304a2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Management.Automation;
using System.Management.Automation.Language;
Expand Down Expand Up @@ -41,11 +42,20 @@ internal class BreakpointService
_debugStateService = debugStateService;
}

public List<Breakpoint> GetBreakpoints()
public async Task<List<Breakpoint>> GetBreakpointsAsync()
{
return BreakpointApiUtils.GetBreakpoints(
_powerShellContextService.CurrentRunspace.Runspace.Debugger,
_debugStateService.RunspaceId);
if (VersionUtils.IsPS7OrGreater)
{
return BreakpointApiUtils.GetBreakpoints(
_powerShellContextService.CurrentRunspace.Runspace.Debugger,
_debugStateService.RunspaceId);
}

// Legacy behavior
PSCommand psCommand = new PSCommand();
psCommand.AddCommand(@"Microsoft.PowerShell.Utility\Get-PSBreakpoint");
IEnumerable<Breakpoint> breakpoints = await _powerShellContextService.ExecuteCommandAsync<Breakpoint>(psCommand);
return breakpoints.ToList();
}

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

PSCommand psCommand = new PSCommand();
psCommand.AddCommand(@"Microsoft.PowerShell.Utility\Get-PSBreakpoint");

if (!string.IsNullOrEmpty(scriptPath))
{
psCommand.AddParameter("Script", scriptPath);
}

psCommand.AddCommand(@"Microsoft.PowerShell.Utility\Remove-PSBreakpoint");

await _powerShellContextService.ExecuteCommandAsync<object>(psCommand);
await _powerShellContextService.ExecuteCommandAsync<object>(psCommand).ConfigureAwait(false);
}
catch (Exception e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ internal class DebugService
if (clearExisting)
{
// Flatten dictionary values into one list and remove them all.
await _breakpointService.RemoveBreakpointsAsync(_breakpointService.GetBreakpoints().Where( i => i is CommandBreakpoint)).ConfigureAwait(false);
await _breakpointService.RemoveBreakpointsAsync((await _breakpointService.GetBreakpointsAsync()).Where( i => i is CommandBreakpoint)).ConfigureAwait(false);
}

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

// Clear the existing breakpoints list for the file
// breakpoints.Clear();
Expand Down

0 comments on commit 23304a2

Please sign in to comment.