diff --git a/src/PowerShellEditorServices/Services/Extension/ExtensionService.cs b/src/PowerShellEditorServices/Services/Extension/ExtensionService.cs index cb4562c43..116273734 100644 --- a/src/PowerShellEditorServices/Services/Extension/ExtensionService.cs +++ b/src/PowerShellEditorServices/Services/Extension/ExtensionService.cs @@ -107,7 +107,7 @@ internal Task InitializeAsync() // Register the editor object in the runspace return ExecutionService.ExecuteDelegateAsync( $"Create ${PSEditorVariableName} object", - ExecutionOptions.Default, + executionOptions: null, (pwsh, _) => pwsh.Runspace.SessionStateProxy.PSVariable.Set(psEditor), CancellationToken.None); } diff --git a/src/PowerShellEditorServices/Services/PowerShell/Console/LegacyReadLine.cs b/src/PowerShellEditorServices/Services/PowerShell/Console/LegacyReadLine.cs index a29fe17f2..c83383e3d 100644 --- a/src/PowerShellEditorServices/Services/PowerShell/Console/LegacyReadLine.cs +++ b/src/PowerShellEditorServices/Services/PowerShell/Console/LegacyReadLine.cs @@ -84,14 +84,14 @@ public override string ReadLine(CancellationToken cancellationToken) .AddParameter("CursorColumn", currentCursorIndex) .AddParameter("Options", null); - currentCompletion = _psesHost.InvokePSCommand(command, PowerShellExecutionOptions.Default, cancellationToken).FirstOrDefault(); + currentCompletion = _psesHost.InvokePSCommand(command, executionOptions: null, cancellationToken).FirstOrDefault(); } else { currentCompletion = _psesHost.InvokePSDelegate( "Legacy readline inline command completion", - ExecutionOptions.Default, - (pwsh, cancellationToken) => CommandCompletion.CompleteInput(inputAfterCompletion, currentCursorIndex, options: null, pwsh), + executionOptions: null, + (pwsh, _) => CommandCompletion.CompleteInput(inputAfterCompletion, currentCursorIndex, options: null, pwsh), cancellationToken); if (currentCompletion.CompletionMatches.Count > 0) @@ -198,7 +198,7 @@ public override string ReadLine(CancellationToken cancellationToken) PSCommand command = new PSCommand() .AddCommand("Get-History"); - currentHistory = _psesHost.InvokePSCommand(command, PowerShellExecutionOptions.Default, cancellationToken); + currentHistory = _psesHost.InvokePSCommand(command, executionOptions: null, cancellationToken); if (currentHistory != null) { diff --git a/src/PowerShellEditorServices/Services/PowerShell/Debugging/DscBreakpointCapability.cs b/src/PowerShellEditorServices/Services/PowerShell/Debugging/DscBreakpointCapability.cs index 0ad294bd0..c13d3e301 100644 --- a/src/PowerShellEditorServices/Services/PowerShell/Debugging/DscBreakpointCapability.cs +++ b/src/PowerShellEditorServices/Services/PowerShell/Debugging/DscBreakpointCapability.cs @@ -164,7 +164,7 @@ public static Task GetDscCapabilityAsync( return psesHost.ExecuteDelegateAsync( nameof(getDscBreakpointCapabilityFunc), - ExecutionOptions.Default, + executionOptions: null, getDscBreakpointCapabilityFunc, cancellationToken); } diff --git a/src/PowerShellEditorServices/Services/PowerShell/Execution/ExecutionOptions.cs b/src/PowerShellEditorServices/Services/PowerShell/Execution/ExecutionOptions.cs index 4965e3415..af5d9e7e9 100644 --- a/src/PowerShellEditorServices/Services/PowerShell/Execution/ExecutionOptions.cs +++ b/src/PowerShellEditorServices/Services/PowerShell/Execution/ExecutionOptions.cs @@ -15,39 +15,16 @@ public enum ExecutionPriority // Generally the executor will do the right thing though; some options just priority over others. public record ExecutionOptions { - public static ExecutionOptions Default = new() - { - Priority = ExecutionPriority.Normal, - MustRunInForeground = false, - InterruptCurrentForeground = false, - }; - - public ExecutionPriority Priority { get; init; } - + public ExecutionPriority Priority { get; init; } = ExecutionPriority.Normal; public bool MustRunInForeground { get; init; } - public bool InterruptCurrentForeground { get; init; } } public record PowerShellExecutionOptions : ExecutionOptions { - public static new PowerShellExecutionOptions Default = new() - { - Priority = ExecutionPriority.Normal, - MustRunInForeground = false, - InterruptCurrentForeground = false, - WriteOutputToHost = false, - WriteInputToHost = false, - ThrowOnError = true, - AddToHistory = false, - }; - public bool WriteOutputToHost { get; init; } - public bool WriteInputToHost { get; init; } - - public bool ThrowOnError { get; init; } - + public bool ThrowOnError { get; init; } = true; public bool AddToHistory { get; init; } } } diff --git a/src/PowerShellEditorServices/Services/PowerShell/Execution/SynchronousDelegateTask.cs b/src/PowerShellEditorServices/Services/PowerShell/Execution/SynchronousDelegateTask.cs index 343f930eb..2bec67fe9 100644 --- a/src/PowerShellEditorServices/Services/PowerShell/Execution/SynchronousDelegateTask.cs +++ b/src/PowerShellEditorServices/Services/PowerShell/Execution/SynchronousDelegateTask.cs @@ -23,7 +23,7 @@ public SynchronousDelegateTask( CancellationToken cancellationToken) : base(logger, cancellationToken) { - ExecutionOptions = executionOptions; + ExecutionOptions = executionOptions ?? new ExecutionOptions(); _representation = representation; _action = action; } @@ -58,7 +58,7 @@ public SynchronousDelegateTask( { _func = func; _representation = representation; - ExecutionOptions = executionOptions; + ExecutionOptions = executionOptions ?? new ExecutionOptions(); } public override ExecutionOptions ExecutionOptions { get; } @@ -94,7 +94,7 @@ public SynchronousPSDelegateTask( _psesHost = psesHost; _action = action; _representation = representation; - ExecutionOptions = executionOptions; + ExecutionOptions = executionOptions ?? new ExecutionOptions(); } public override ExecutionOptions ExecutionOptions { get; } @@ -131,7 +131,7 @@ public SynchronousPSDelegateTask( _psesHost = psesHost; _func = func; _representation = representation; - ExecutionOptions = executionOptions; + ExecutionOptions = executionOptions ?? new ExecutionOptions(); } public override ExecutionOptions ExecutionOptions { get; } diff --git a/src/PowerShellEditorServices/Services/PowerShell/Execution/SynchronousPowerShellTask.cs b/src/PowerShellEditorServices/Services/PowerShell/Execution/SynchronousPowerShellTask.cs index b438e84cc..c3a1132ad 100644 --- a/src/PowerShellEditorServices/Services/PowerShell/Execution/SynchronousPowerShellTask.cs +++ b/src/PowerShellEditorServices/Services/PowerShell/Execution/SynchronousPowerShellTask.cs @@ -36,7 +36,7 @@ public SynchronousPowerShellTask( _logger = logger; _psesHost = psesHost; _psCommand = command; - PowerShellExecutionOptions = executionOptions; + PowerShellExecutionOptions = executionOptions ?? new PowerShellExecutionOptions(); } public PowerShellExecutionOptions PowerShellExecutionOptions { get; } diff --git a/src/PowerShellEditorServices/Services/PowerShell/Host/PsesInternalHost.cs b/src/PowerShellEditorServices/Services/PowerShell/Host/PsesInternalHost.cs index d7c34faee..5e790037d 100644 --- a/src/PowerShellEditorServices/Services/PowerShell/Host/PsesInternalHost.cs +++ b/src/PowerShellEditorServices/Services/PowerShell/Host/PsesInternalHost.cs @@ -307,7 +307,8 @@ public Task ExecuteDelegateAsync( Func func, CancellationToken cancellationToken) { - return InvokeTaskOnPipelineThreadAsync(new SynchronousPSDelegateTask(_logger, this, representation, executionOptions ?? ExecutionOptions.Default, func, cancellationToken)); + return InvokeTaskOnPipelineThreadAsync( + new SynchronousPSDelegateTask(_logger, this, representation, executionOptions, func, cancellationToken)); } public Task ExecuteDelegateAsync( @@ -316,7 +317,8 @@ public Task ExecuteDelegateAsync( Action action, CancellationToken cancellationToken) { - return InvokeTaskOnPipelineThreadAsync(new SynchronousPSDelegateTask(_logger, this, representation, executionOptions ?? ExecutionOptions.Default, action, cancellationToken)); + return InvokeTaskOnPipelineThreadAsync( + new SynchronousPSDelegateTask(_logger, this, representation, executionOptions, action, cancellationToken)); } public Task ExecuteDelegateAsync( @@ -325,7 +327,8 @@ public Task ExecuteDelegateAsync( Func func, CancellationToken cancellationToken) { - return InvokeTaskOnPipelineThreadAsync(new SynchronousDelegateTask(_logger, representation, executionOptions ?? ExecutionOptions.Default, func, cancellationToken)); + return InvokeTaskOnPipelineThreadAsync( + new SynchronousDelegateTask(_logger, representation, executionOptions, func, cancellationToken)); } public Task ExecuteDelegateAsync( @@ -334,7 +337,8 @@ public Task ExecuteDelegateAsync( Action action, CancellationToken cancellationToken) { - return InvokeTaskOnPipelineThreadAsync(new SynchronousDelegateTask(_logger, representation, executionOptions ?? ExecutionOptions.Default, action, cancellationToken)); + return InvokeTaskOnPipelineThreadAsync( + new SynchronousDelegateTask(_logger, representation, executionOptions, action, cancellationToken)); } public Task> ExecutePSCommandAsync( @@ -342,18 +346,17 @@ public Task> ExecutePSCommandAsync( CancellationToken cancellationToken, PowerShellExecutionOptions executionOptions = null) { - return InvokeTaskOnPipelineThreadAsync(new SynchronousPowerShellTask( - _logger, - this, - psCommand, - executionOptions ?? PowerShellExecutionOptions.Default, - cancellationToken)); + return InvokeTaskOnPipelineThreadAsync( + new SynchronousPowerShellTask(_logger, this, psCommand, executionOptions, cancellationToken)); } public Task ExecutePSCommandAsync( PSCommand psCommand, CancellationToken cancellationToken, - PowerShellExecutionOptions executionOptions = null) => ExecutePSCommandAsync(psCommand, cancellationToken, executionOptions); + PowerShellExecutionOptions executionOptions = null) + { + return ExecutePSCommandAsync(psCommand, cancellationToken, executionOptions); + } public TResult InvokeDelegate(string representation, ExecutionOptions executionOptions, Func func, CancellationToken cancellationToken) { @@ -374,7 +377,9 @@ public IReadOnlyList InvokePSCommand(PSCommand psCommand, Powe } public void InvokePSCommand(PSCommand psCommand, PowerShellExecutionOptions executionOptions, CancellationToken cancellationToken) - => InvokePSCommand(psCommand, executionOptions, cancellationToken); + { + InvokePSCommand(psCommand, executionOptions, cancellationToken); + } public TResult InvokePSDelegate(string representation, ExecutionOptions executionOptions, Func func, CancellationToken cancellationToken) { @@ -662,7 +667,7 @@ private void DoOneRepl(CancellationToken cancellationToken) private string GetPrompt(CancellationToken cancellationToken) { var command = new PSCommand().AddCommand("prompt"); - IReadOnlyList results = InvokePSCommand(command, PowerShellExecutionOptions.Default, cancellationToken); + IReadOnlyList results = InvokePSCommand(command, executionOptions: null, cancellationToken); string prompt = results.Count > 0 ? results[0] : DefaultPrompt; if (CurrentRunspace.RunspaceOrigin != RunspaceOrigin.Local) @@ -846,7 +851,7 @@ private void OnPowerShellIdle(CancellationToken idleCancellationToken) // to force event processing if (runPipelineForEventProcessing) { - InvokePSCommand(new PSCommand().AddScript("0", useLocalScope: true), PowerShellExecutionOptions.Default, CancellationToken.None); + InvokePSCommand(new PSCommand().AddScript("0", useLocalScope: true), executionOptions: null, CancellationToken.None); } } diff --git a/src/PowerShellEditorServices/Services/PowerShell/Utility/CommandHelpers.cs b/src/PowerShellEditorServices/Services/PowerShell/Utility/CommandHelpers.cs index 031727b02..fffb0c1c9 100644 --- a/src/PowerShellEditorServices/Services/PowerShell/Utility/CommandHelpers.cs +++ b/src/PowerShellEditorServices/Services/PowerShell/Utility/CommandHelpers.cs @@ -183,7 +183,7 @@ public static async Task GetCommandSynopsisAsync( IEnumerable aliases = await executionService.ExecuteDelegateAsync>( nameof(GetAliasesAsync), - Execution.ExecutionOptions.Default, + executionOptions: null, (pwsh, _) => { CommandInvocationIntrinsics invokeCommand = pwsh.Runspace.SessionStateProxy.InvokeCommand; diff --git a/src/PowerShellEditorServices/Services/Workspace/RemoteFileManagerService.cs b/src/PowerShellEditorServices/Services/Workspace/RemoteFileManagerService.cs index 6db4fc4d9..4ff1b98f6 100644 --- a/src/PowerShellEditorServices/Services/Workspace/RemoteFileManagerService.cs +++ b/src/PowerShellEditorServices/Services/Workspace/RemoteFileManagerService.cs @@ -657,8 +657,8 @@ private async void HandlePSEventReceivedAsync(object sender, PSEventArgs args) private Task RegisterPSEditFunctionAsync() => _executionService.ExecuteDelegateAsync( "Register psedit function", - ExecutionOptions.Default, - (pwsh, cancellationToken) => RegisterPSEditFunction(pwsh.Runspace), + executionOptions: null, + (pwsh, _) => RegisterPSEditFunction(pwsh.Runspace), CancellationToken.None); private void RegisterPSEditFunction(Runspace runspace)