Skip to content

Replace superfluous Default member with default values #1693

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ public override string ReadLine(CancellationToken cancellationToken)
.AddParameter("CursorColumn", currentCursorIndex)
.AddParameter("Options", null);

currentCompletion = _psesHost.InvokePSCommand<CommandCompletion>(command, PowerShellExecutionOptions.Default, cancellationToken).FirstOrDefault();
currentCompletion = _psesHost.InvokePSCommand<CommandCompletion>(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)
Expand Down Expand Up @@ -198,7 +198,7 @@ public override string ReadLine(CancellationToken cancellationToken)
PSCommand command = new PSCommand()
.AddCommand("Get-History");

currentHistory = _psesHost.InvokePSCommand<PSObject>(command, PowerShellExecutionOptions.Default, cancellationToken);
currentHistory = _psesHost.InvokePSCommand<PSObject>(command, executionOptions: null, cancellationToken);

if (currentHistory != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public static Task<DscBreakpointCapability> GetDscCapabilityAsync(

return psesHost.ExecuteDelegateAsync<DscBreakpointCapability>(
nameof(getDscBreakpointCapabilityFunc),
ExecutionOptions.Default,
executionOptions: null,
getDscBreakpointCapabilityFunc,
cancellationToken);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public SynchronousDelegateTask(
CancellationToken cancellationToken)
: base(logger, cancellationToken)
{
ExecutionOptions = executionOptions;
ExecutionOptions = executionOptions ?? new ExecutionOptions();
_representation = representation;
_action = action;
}
Expand Down Expand Up @@ -58,7 +58,7 @@ public SynchronousDelegateTask(
{
_func = func;
_representation = representation;
ExecutionOptions = executionOptions;
ExecutionOptions = executionOptions ?? new ExecutionOptions();
}

public override ExecutionOptions ExecutionOptions { get; }
Expand Down Expand Up @@ -94,7 +94,7 @@ public SynchronousPSDelegateTask(
_psesHost = psesHost;
_action = action;
_representation = representation;
ExecutionOptions = executionOptions;
ExecutionOptions = executionOptions ?? new ExecutionOptions();
}

public override ExecutionOptions ExecutionOptions { get; }
Expand Down Expand Up @@ -131,7 +131,7 @@ public SynchronousPSDelegateTask(
_psesHost = psesHost;
_func = func;
_representation = representation;
ExecutionOptions = executionOptions;
ExecutionOptions = executionOptions ?? new ExecutionOptions();
}

public override ExecutionOptions ExecutionOptions { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public SynchronousPowerShellTask(
_logger = logger;
_psesHost = psesHost;
_psCommand = command;
PowerShellExecutionOptions = executionOptions;
PowerShellExecutionOptions = executionOptions ?? new PowerShellExecutionOptions();
}

public PowerShellExecutionOptions PowerShellExecutionOptions { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,8 @@ public Task<TResult> ExecuteDelegateAsync<TResult>(
Func<PowerShell, CancellationToken, TResult> func,
CancellationToken cancellationToken)
{
return InvokeTaskOnPipelineThreadAsync(new SynchronousPSDelegateTask<TResult>(_logger, this, representation, executionOptions ?? ExecutionOptions.Default, func, cancellationToken));
return InvokeTaskOnPipelineThreadAsync(
new SynchronousPSDelegateTask<TResult>(_logger, this, representation, executionOptions, func, cancellationToken));
}

public Task ExecuteDelegateAsync(
Expand All @@ -316,7 +317,8 @@ public Task ExecuteDelegateAsync(
Action<PowerShell, CancellationToken> 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<TResult> ExecuteDelegateAsync<TResult>(
Expand All @@ -325,7 +327,8 @@ public Task<TResult> ExecuteDelegateAsync<TResult>(
Func<CancellationToken, TResult> func,
CancellationToken cancellationToken)
{
return InvokeTaskOnPipelineThreadAsync(new SynchronousDelegateTask<TResult>(_logger, representation, executionOptions ?? ExecutionOptions.Default, func, cancellationToken));
return InvokeTaskOnPipelineThreadAsync(
new SynchronousDelegateTask<TResult>(_logger, representation, executionOptions, func, cancellationToken));
}

public Task ExecuteDelegateAsync(
Expand All @@ -334,26 +337,26 @@ public Task ExecuteDelegateAsync(
Action<CancellationToken> 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<IReadOnlyList<TResult>> ExecutePSCommandAsync<TResult>(
PSCommand psCommand,
CancellationToken cancellationToken,
PowerShellExecutionOptions executionOptions = null)
{
return InvokeTaskOnPipelineThreadAsync(new SynchronousPowerShellTask<TResult>(
_logger,
this,
psCommand,
executionOptions ?? PowerShellExecutionOptions.Default,
cancellationToken));
return InvokeTaskOnPipelineThreadAsync(
new SynchronousPowerShellTask<TResult>(_logger, this, psCommand, executionOptions, cancellationToken));
}

public Task ExecutePSCommandAsync(
PSCommand psCommand,
CancellationToken cancellationToken,
PowerShellExecutionOptions executionOptions = null) => ExecutePSCommandAsync<PSObject>(psCommand, cancellationToken, executionOptions);
PowerShellExecutionOptions executionOptions = null)
{
return ExecutePSCommandAsync<PSObject>(psCommand, cancellationToken, executionOptions);
}

public TResult InvokeDelegate<TResult>(string representation, ExecutionOptions executionOptions, Func<CancellationToken, TResult> func, CancellationToken cancellationToken)
{
Expand All @@ -374,7 +377,9 @@ public IReadOnlyList<TResult> InvokePSCommand<TResult>(PSCommand psCommand, Powe
}

public void InvokePSCommand(PSCommand psCommand, PowerShellExecutionOptions executionOptions, CancellationToken cancellationToken)
=> InvokePSCommand<PSObject>(psCommand, executionOptions, cancellationToken);
{
InvokePSCommand<PSObject>(psCommand, executionOptions, cancellationToken);
}

public TResult InvokePSDelegate<TResult>(string representation, ExecutionOptions executionOptions, Func<PowerShell, CancellationToken, TResult> func, CancellationToken cancellationToken)
{
Expand Down Expand Up @@ -662,7 +667,7 @@ private void DoOneRepl(CancellationToken cancellationToken)
private string GetPrompt(CancellationToken cancellationToken)
{
var command = new PSCommand().AddCommand("prompt");
IReadOnlyList<string> results = InvokePSCommand<string>(command, PowerShellExecutionOptions.Default, cancellationToken);
IReadOnlyList<string> results = InvokePSCommand<string>(command, executionOptions: null, cancellationToken);
string prompt = results.Count > 0 ? results[0] : DefaultPrompt;

if (CurrentRunspace.RunspaceOrigin != RunspaceOrigin.Local)
Expand Down Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public static async Task<string> GetCommandSynopsisAsync(

IEnumerable<CommandInfo> aliases = await executionService.ExecuteDelegateAsync<IEnumerable<CommandInfo>>(
nameof(GetAliasesAsync),
Execution.ExecutionOptions.Default,
executionOptions: null,
(pwsh, _) =>
{
CommandInvocationIntrinsics invokeCommand = pwsh.Runspace.SessionStateProxy.InvokeCommand;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down