Skip to content

Commit b433b0f

Browse files
Print prompt and command when WriteInputToHost is true (#1691)
1 parent f3cea93 commit b433b0f

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

src/PowerShellEditorServices/Services/PowerShell/Execution/SynchronousPowerShellTask.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
using Microsoft.Extensions.Logging;
5-
using Microsoft.PowerShell.EditorServices.Services.PowerShell.Host;
6-
using Microsoft.PowerShell.EditorServices.Services.PowerShell.Utility;
7-
using Microsoft.PowerShell.EditorServices.Utility;
84
using System;
95
using System.Collections.Generic;
106
using System.Collections.ObjectModel;
117
using System.Management.Automation;
128
using System.Management.Automation.Remoting;
139
using System.Threading;
10+
using Microsoft.Extensions.Logging;
11+
using Microsoft.PowerShell.EditorServices.Services.PowerShell.Host;
12+
using Microsoft.PowerShell.EditorServices.Services.PowerShell.Utility;
13+
using Microsoft.PowerShell.EditorServices.Utility;
1414
using SMA = System.Management.Automation;
1515

1616
namespace Microsoft.PowerShell.EditorServices.Services.PowerShell.Execution
@@ -49,7 +49,7 @@ public override IReadOnlyList<TResult> Run(CancellationToken cancellationToken)
4949

5050
if (PowerShellExecutionOptions.WriteInputToHost)
5151
{
52-
_psesHost.UI.WriteLine(_psCommand.GetInvocationText());
52+
_psesHost.WriteWithPrompt(_psCommand, cancellationToken);
5353
}
5454

5555
return _pwsh.Runspace.Debugger.InBreakpoint
@@ -234,7 +234,7 @@ private void StopDebuggerIfRemoteDebugSessionFailed()
234234

235235
foreach (PSObject output in outputCollection)
236236
{
237-
if (object.Equals(output?.BaseObject, false))
237+
if (Equals(output?.BaseObject, false))
238238
{
239239
_psesHost.DebugContext.ProcessDebuggerResult(new DebuggerCommandResults(DebuggerResumeAction.Stop, evaluatedByDebugger: true));
240240
_logger.LogWarning("Cancelling debug session due to remote command cancellation causing the end of remote debugging session");

src/PowerShellEditorServices/Services/PowerShell/Host/PsesInternalHost.cs

+13
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,19 @@ private string GetPrompt(CancellationToken cancellationToken)
674674
return prompt;
675675
}
676676

677+
/// <summary>
678+
/// This is used to write the invocation text of a command with the user's prompt so that,
679+
/// for example, F8 (evaluate selection) appears as if the user typed it. Used when
680+
/// 'WriteInputToHost' is true.
681+
/// </summary>
682+
/// <param name="command">The PSCommand we'll print after the prompt.</param>
683+
/// <param name="cancellationToken"></param>
684+
public void WriteWithPrompt(PSCommand command, CancellationToken cancellationToken)
685+
{
686+
UI.Write(GetPrompt(cancellationToken));
687+
UI.Write(command.GetInvocationText());
688+
}
689+
677690
private string InvokeReadLine(CancellationToken cancellationToken)
678691
{
679692
return _readLineProvider.ReadLine.ReadLine(cancellationToken);

0 commit comments

Comments
 (0)