Merged
Changes from all commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Failed to load files.
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,7 +10,6 @@
using Microsoft.Extensions.Logging;
using Microsoft.PowerShell.EditorServices.Services.DebugAdapter;
using Microsoft.PowerShell.EditorServices.Services.PowerShell.Execution;
using Microsoft.PowerShell.EditorServices.Services.PowerShell.Host;
using Microsoft.PowerShell.EditorServices.Services.PowerShell.Runspace;

namespace Microsoft.PowerShell.EditorServices.Services.PowerShell.Debugging
Expand DownExpand Up@@ -54,10 +53,7 @@ public async Task<IReadOnlyList<BreakpointDetails>> SetLineBreakpointsAsync(
? $"Enable-DscDebug -Breakpoint {hashtableString}"
: "Disable-DscDebug");

await executionService.ExecutePSCommandAsync(
dscCommand,
CancellationToken.None)
.ConfigureAwait(false);
await executionService.ExecutePSCommandAsync(dscCommand, CancellationToken.None).ConfigureAwait(false);

// Verify all the breakpoints and return them
foreach (BreakpointDetails breakpoint in breakpoints)
Expand All@@ -80,7 +76,7 @@ public bool IsDscResourcePath(string scriptPath)
public static async Task<DscBreakpointCapability> GetDscCapabilityAsync(
ILogger logger,
IRunspaceInfo currentRunspace,
PsesInternalHost psesHost)
IInternalPowerShellExecutionService executionService)
{
// DSC support is enabled only for Windows PowerShell.
if ((currentRunspace.PowerShellVersionDetails.Version.Major >= 6) &&
Expand All@@ -92,16 +88,13 @@ public static async Task<DscBreakpointCapability> GetDscCapabilityAsync(
if (!isDscInstalled.HasValue)
{
PSCommand psCommand = new PSCommand()
.AddScript($"$global:{DebugService.PsesGlobalVariableNamePrefix}prevProgressPreference = $ProgressPreference")
.AddScript("$ProgressPreference = 'SilentlyContinue'")
.AddCommand(@"Microsoft.PowerShell.Core\Import-Module")
.AddParameter("Name", "PSDesiredStateConfiguration")
.AddParameter("PassThru")
.AddParameter("ErrorAction", ActionPreference.Ignore)
.AddScript($"$ProgressPreference = $global:{DebugService.PsesGlobalVariableNamePrefix}prevProgressPreference");
.AddParameter("ErrorAction", ActionPreference.Ignore);

IReadOnlyList<PSModuleInfo> dscModule =
await psesHost.ExecutePSCommandAsync<PSModuleInfo>(
await executionService.ExecutePSCommandAsync<PSModuleInfo>(
psCommand,
CancellationToken.None,
new PowerShellExecutionOptions { ThrowOnError = false })
Expand All@@ -113,19 +106,29 @@ await psesHost.ExecutePSCommandAsync<PSModuleInfo>(

if (isDscInstalled.Value)
{
PSCommand psCommand = new PSCommand()
.AddCommand("Get-DscResource")
.AddCommand("Select-Object")
.AddParameter("ExpandProperty", "ParentPath");
// Note that __psEditorServices_ is DebugService.PsesGlobalVariableNamePrefix but
// it's notoriously difficult to interpolate it in this script, which has to be a
// single script to guarantee everything is run at once.
PSCommand psCommand = new PSCommand().AddScript(
"""
try {
$global:__psEditorServices_prevProgressPreference = $ProgressPreference
$global:ProgressPreference = 'SilentlyContinue'
return Get-DscResource | Select-Object -ExpandProperty ParentPath
} finally {
$ProgressPreference = $global:__psEditorServices_prevProgressPreference
}
""");

IReadOnlyList<string> resourcePaths =
await psesHost.ExecutePSCommandAsync<string>(
await executionService.ExecutePSCommandAsync<string>(
psCommand,
CancellationToken.None,
new PowerShellExecutionOptions { ThrowOnError = false }
).ConfigureAwait(false);

logger.LogTrace($"DSC resources found: {resourcePaths.Count}");

return new DscBreakpointCapability
{
dscResourceRootPaths = resourcePaths.ToArray()
Expand Down