diff --git a/src/PowerShellEditorServices/Services/PowerShell/Execution/SynchronousPowerShellTask.cs b/src/PowerShellEditorServices/Services/PowerShell/Execution/SynchronousPowerShellTask.cs index 4511fb1f5..b438e84cc 100644 --- a/src/PowerShellEditorServices/Services/PowerShell/Execution/SynchronousPowerShellTask.cs +++ b/src/PowerShellEditorServices/Services/PowerShell/Execution/SynchronousPowerShellTask.cs @@ -1,16 +1,16 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -using Microsoft.Extensions.Logging; -using Microsoft.PowerShell.EditorServices.Services.PowerShell.Host; -using Microsoft.PowerShell.EditorServices.Services.PowerShell.Utility; -using Microsoft.PowerShell.EditorServices.Utility; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Management.Automation; using System.Management.Automation.Remoting; using System.Threading; +using Microsoft.Extensions.Logging; +using Microsoft.PowerShell.EditorServices.Services.PowerShell.Host; +using Microsoft.PowerShell.EditorServices.Services.PowerShell.Utility; +using Microsoft.PowerShell.EditorServices.Utility; using SMA = System.Management.Automation; namespace Microsoft.PowerShell.EditorServices.Services.PowerShell.Execution @@ -49,7 +49,7 @@ public override IReadOnlyList Run(CancellationToken cancellationToken) if (PowerShellExecutionOptions.WriteInputToHost) { - _psesHost.UI.WriteLine(_psCommand.GetInvocationText()); + _psesHost.WriteWithPrompt(_psCommand, cancellationToken); } return _pwsh.Runspace.Debugger.InBreakpoint @@ -234,7 +234,7 @@ private void StopDebuggerIfRemoteDebugSessionFailed() foreach (PSObject output in outputCollection) { - if (object.Equals(output?.BaseObject, false)) + if (Equals(output?.BaseObject, false)) { _psesHost.DebugContext.ProcessDebuggerResult(new DebuggerCommandResults(DebuggerResumeAction.Stop, evaluatedByDebugger: true)); _logger.LogWarning("Cancelling debug session due to remote command cancellation causing the end of remote debugging session"); diff --git a/src/PowerShellEditorServices/Services/PowerShell/Host/PsesInternalHost.cs b/src/PowerShellEditorServices/Services/PowerShell/Host/PsesInternalHost.cs index 04c8b3d35..5dd4c30c2 100644 --- a/src/PowerShellEditorServices/Services/PowerShell/Host/PsesInternalHost.cs +++ b/src/PowerShellEditorServices/Services/PowerShell/Host/PsesInternalHost.cs @@ -674,6 +674,19 @@ private string GetPrompt(CancellationToken cancellationToken) return prompt; } + /// + /// This is used to write the invocation text of a command with the user's prompt so that, + /// for example, F8 (evaluate selection) appears as if the user typed it. Used when + /// 'WriteInputToHost' is true. + /// + /// The PSCommand we'll print after the prompt. + /// + public void WriteWithPrompt(PSCommand command, CancellationToken cancellationToken) + { + UI.Write(GetPrompt(cancellationToken)); + UI.Write(command.GetInvocationText()); + } + private string InvokeReadLine(CancellationToken cancellationToken) { return _readLineProvider.ReadLine.ReadLine(cancellationToken);