Skip to content

Print prompt and command when WriteInputToHost is true #1691

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 1, 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
@@ -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
Expand Down Expand Up @@ -49,7 +49,7 @@ public override IReadOnlyList<TResult> Run(CancellationToken cancellationToken)

if (PowerShellExecutionOptions.WriteInputToHost)
{
_psesHost.UI.WriteLine(_psCommand.GetInvocationText());
_psesHost.WriteWithPrompt(_psCommand, cancellationToken);
}

return _pwsh.Runspace.Debugger.InBreakpoint
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,19 @@ private string GetPrompt(CancellationToken cancellationToken)
return prompt;
}

/// <summary>
/// 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.
/// </summary>
/// <param name="command">The PSCommand we'll print after the prompt.</param>
/// <param name="cancellationToken"></param>
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);
Expand Down