From 4974016fec498438cbb4872439b1118d2e29c3be Mon Sep 17 00:00:00 2001 From: Andy Jordan <2226434+andyleejordan@users.noreply.github.com> Date: Fri, 15 Sep 2023 14:31:31 -0700 Subject: [PATCH] Wrap import of DSC module with `ProgressPreference = SilentlyContinue` And set it back afterwards. Since it has `ErrorAction = Ignore` it should always get set back correctly. This prevents the progress pane from getting stuck in certain circumstances. --- .../Services/DebugAdapter/DebugService.cs | 2 +- .../Services/DebugAdapter/Debugging/BreakpointApiUtils.cs | 4 +--- .../PowerShell/Debugging/DscBreakpointCapability.cs | 7 +++++-- .../Services/PowerShell/Utility/PowerShellExtensions.cs | 4 ++-- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/PowerShellEditorServices/Services/DebugAdapter/DebugService.cs b/src/PowerShellEditorServices/Services/DebugAdapter/DebugService.cs index 9328e5440..43c54c17a 100644 --- a/src/PowerShellEditorServices/Services/DebugAdapter/DebugService.cs +++ b/src/PowerShellEditorServices/Services/DebugAdapter/DebugService.cs @@ -30,7 +30,7 @@ internal class DebugService { #region Fields - private const string PsesGlobalVariableNamePrefix = "__psEditorServices_"; + internal const string PsesGlobalVariableNamePrefix = "__psEditorServices_"; private const string TemporaryScriptFileName = "Script Listing.ps1"; private readonly ILogger _logger; diff --git a/src/PowerShellEditorServices/Services/DebugAdapter/Debugging/BreakpointApiUtils.cs b/src/PowerShellEditorServices/Services/DebugAdapter/Debugging/BreakpointApiUtils.cs index d5ce11927..7884fbda5 100644 --- a/src/PowerShellEditorServices/Services/DebugAdapter/Debugging/BreakpointApiUtils.cs +++ b/src/PowerShellEditorServices/Services/DebugAdapter/Debugging/BreakpointApiUtils.cs @@ -18,8 +18,6 @@ internal static class BreakpointApiUtils { #region Private Static Fields - private const string s_psesGlobalVariableNamePrefix = "__psEditorServices_"; - private static readonly Lazy> s_setLineBreakpointLazy; private static readonly Lazy> s_setCommandBreakpointLazy; @@ -199,7 +197,7 @@ public static ScriptBlock GetBreakpointActionScriptBlock(string condition, strin int incrementResult = Interlocked.Increment(ref breakpointHitCounter); string globalHitCountVarName = - $"$global:{s_psesGlobalVariableNamePrefix}BreakHitCounter_{incrementResult}"; + $"$global:{DebugService.PsesGlobalVariableNamePrefix}BreakHitCounter_{incrementResult}"; builder.Insert(0, $"if (++{globalHitCountVarName} -eq {parsedHitCount}) {{ ") .Append(" }"); diff --git a/src/PowerShellEditorServices/Services/PowerShell/Debugging/DscBreakpointCapability.cs b/src/PowerShellEditorServices/Services/PowerShell/Debugging/DscBreakpointCapability.cs index da486ccbc..c929f4bcc 100644 --- a/src/PowerShellEditorServices/Services/PowerShell/Debugging/DscBreakpointCapability.cs +++ b/src/PowerShellEditorServices/Services/PowerShell/Debugging/DscBreakpointCapability.cs @@ -92,10 +92,13 @@ public static async Task 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("Name", "PSDesiredStateConfiguration") .AddParameter("PassThru") - .AddParameter("ErrorAction", ActionPreference.Ignore); + .AddParameter("ErrorAction", ActionPreference.Ignore) + .AddScript($"$ProgressPreference = $global:{DebugService.PsesGlobalVariableNamePrefix}prevProgressPreference"); IReadOnlyList dscModule = await psesHost.ExecutePSCommandAsync( diff --git a/src/PowerShellEditorServices/Services/PowerShell/Utility/PowerShellExtensions.cs b/src/PowerShellEditorServices/Services/PowerShell/Utility/PowerShellExtensions.cs index 1032e70f5..f7ef51ab9 100644 --- a/src/PowerShellEditorServices/Services/PowerShell/Utility/PowerShellExtensions.cs +++ b/src/PowerShellEditorServices/Services/PowerShell/Utility/PowerShellExtensions.cs @@ -140,7 +140,7 @@ public static void SetCorrectExecutionPolicy(this PowerShell pwsh, ILogger logge // Calling the cmdlet is the simplest way to do that IReadOnlyList policies = pwsh .AddCommand(@"Microsoft.PowerShell.Security\Get-ExecutionPolicy") - .AddParameter("-List") + .AddParameter("List") .InvokeAndClear(); // The policies come out in the following order: @@ -223,7 +223,7 @@ public static void LoadProfiles(this PowerShell pwsh, ProfilePathInfo profilePat public static void ImportModule(this PowerShell pwsh, string moduleNameOrPath) { pwsh.AddCommand(@"Microsoft.PowerShell.Core\Import-Module") - .AddParameter("-Name", moduleNameOrPath) + .AddParameter("Name", moduleNameOrPath) .InvokeAndClear(); }