Skip to content

Commit 4974016

Browse files
committed
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.
1 parent a6b4a92 commit 4974016

File tree

4 files changed

+9
-8
lines changed

4 files changed

+9
-8
lines changed

src/PowerShellEditorServices/Services/DebugAdapter/DebugService.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ internal class DebugService
3030
{
3131
#region Fields
3232

33-
private const string PsesGlobalVariableNamePrefix = "__psEditorServices_";
33+
internal const string PsesGlobalVariableNamePrefix = "__psEditorServices_";
3434
private const string TemporaryScriptFileName = "Script Listing.ps1";
3535

3636
private readonly ILogger _logger;

src/PowerShellEditorServices/Services/DebugAdapter/Debugging/BreakpointApiUtils.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ internal static class BreakpointApiUtils
1818
{
1919
#region Private Static Fields
2020

21-
private const string s_psesGlobalVariableNamePrefix = "__psEditorServices_";
22-
2321
private static readonly Lazy<Func<Debugger, string, int, int, ScriptBlock, int?, LineBreakpoint>> s_setLineBreakpointLazy;
2422

2523
private static readonly Lazy<Func<Debugger, string, ScriptBlock, string, int?, CommandBreakpoint>> s_setCommandBreakpointLazy;
@@ -199,7 +197,7 @@ public static ScriptBlock GetBreakpointActionScriptBlock(string condition, strin
199197
int incrementResult = Interlocked.Increment(ref breakpointHitCounter);
200198

201199
string globalHitCountVarName =
202-
$"$global:{s_psesGlobalVariableNamePrefix}BreakHitCounter_{incrementResult}";
200+
$"$global:{DebugService.PsesGlobalVariableNamePrefix}BreakHitCounter_{incrementResult}";
203201

204202
builder.Insert(0, $"if (++{globalHitCountVarName} -eq {parsedHitCount}) {{ ")
205203
.Append(" }");

src/PowerShellEditorServices/Services/PowerShell/Debugging/DscBreakpointCapability.cs

+5-2
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,13 @@ public static async Task<DscBreakpointCapability> GetDscCapabilityAsync(
9292
if (!isDscInstalled.HasValue)
9393
{
9494
PSCommand psCommand = new PSCommand()
95+
.AddScript($"$global:{DebugService.PsesGlobalVariableNamePrefix}prevProgressPreference = $ProgressPreference")
96+
.AddScript("$ProgressPreference = 'SilentlyContinue'")
9597
.AddCommand(@"Microsoft.PowerShell.Core\Import-Module")
96-
.AddParameter("-Name", "PSDesiredStateConfiguration")
98+
.AddParameter("Name", "PSDesiredStateConfiguration")
9799
.AddParameter("PassThru")
98-
.AddParameter("ErrorAction", ActionPreference.Ignore);
100+
.AddParameter("ErrorAction", ActionPreference.Ignore)
101+
.AddScript($"$ProgressPreference = $global:{DebugService.PsesGlobalVariableNamePrefix}prevProgressPreference");
99102

100103
IReadOnlyList<PSModuleInfo> dscModule =
101104
await psesHost.ExecutePSCommandAsync<PSModuleInfo>(

src/PowerShellEditorServices/Services/PowerShell/Utility/PowerShellExtensions.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public static void SetCorrectExecutionPolicy(this PowerShell pwsh, ILogger logge
140140
// Calling the cmdlet is the simplest way to do that
141141
IReadOnlyList<PSObject> policies = pwsh
142142
.AddCommand(@"Microsoft.PowerShell.Security\Get-ExecutionPolicy")
143-
.AddParameter("-List")
143+
.AddParameter("List")
144144
.InvokeAndClear<PSObject>();
145145

146146
// The policies come out in the following order:
@@ -223,7 +223,7 @@ public static void LoadProfiles(this PowerShell pwsh, ProfilePathInfo profilePat
223223
public static void ImportModule(this PowerShell pwsh, string moduleNameOrPath)
224224
{
225225
pwsh.AddCommand(@"Microsoft.PowerShell.Core\Import-Module")
226-
.AddParameter("-Name", moduleNameOrPath)
226+
.AddParameter("Name", moduleNameOrPath)
227227
.InvokeAndClear();
228228
}
229229

0 commit comments

Comments
 (0)