Skip to content
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

Fix debugging output location #1162

Merged
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 @@ -199,7 +199,7 @@ public static PowerShellContextService Create(

EditorServicesPSHostUserInterface hostUserInterface =
hostStartupInfo.ConsoleReplEnabled
? (EditorServicesPSHostUserInterface)new TerminalPSHostUserInterface(powerShellContext, logger, hostStartupInfo.PSHost)
? (EditorServicesPSHostUserInterface) new TerminalPSHostUserInterface(powerShellContext, hostStartupInfo.PSHost, shouldUsePSReadLine, logger)
: new ProtocolPSHostUserInterface(languageServer, powerShellContext, logger);

EditorServicesPSHost psHost =
Expand Down Expand Up @@ -680,7 +680,9 @@ public async Task<IEnumerable<TResult>> ExecuteCommandAsync<TResult>(
runspaceHandle = await this.GetRunspaceHandleAsync(executionOptions.IsReadLine).ConfigureAwait(false);
if (executionOptions.WriteInputToHost)
{
this.WriteOutput(psCommand.Commands[0].CommandText, true);
this.WriteOutput(
psCommand.Commands[0].CommandText,
includeNewLine: true);
}

if (executionTarget == ExecutionTarget.Debugger)
Expand Down Expand Up @@ -1074,18 +1076,17 @@ public async Task ExecuteScriptWithArgsAsync(string script, string arguments = n
command.AddCommand(script, false);
}

if (writeInputToHost)
{
this.WriteOutput(
script + Environment.NewLine,
true);
}

await this.ExecuteCommandAsync<object>(
command,
errorMessages: null,
sendOutputToHost: true,
addToHistory: true).ConfigureAwait(false);
command,
errorMessages: null,
new ExecutionOptions
{
WriteInputToHost = true,
WriteOutputToHost = true,
WriteErrorsToHost = true,
AddToHistory = true,
}).ConfigureAwait(false);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public abstract class EditorServicesPSHostUserInterface :

private readonly ConcurrentDictionary<ProgressKey, object> currentProgressMessages =
new ConcurrentDictionary<ProgressKey, object>();

private readonly bool _isPSReadLineEnabled;
private PromptHandler activePromptHandler;
private PSHostRawUserInterface rawUserInterface;
private CancellationTokenSource commandLoopCancellationToken;
Expand Down Expand Up @@ -104,11 +106,13 @@ public abstract class EditorServicesPSHostUserInterface :
public EditorServicesPSHostUserInterface(
PowerShellContextService powerShellContext,
PSHostRawUserInterface rawUserInterface,
bool isPSReadLineEnabled,
ILogger logger)
{
this.Logger = logger;
this.powerShellContext = powerShellContext;
this.rawUserInterface = rawUserInterface;
_isPSReadLineEnabled = isPSReadLineEnabled;

this.powerShellContext.DebuggerStop += PowerShellContext_DebuggerStop;
this.powerShellContext.DebuggerResumed += PowerShellContext_DebuggerResumed;
Expand Down Expand Up @@ -850,7 +854,12 @@ private async Task StartReplLoopAsync(CancellationToken cancellationToken)
}
finally
{
if (!cancellationToken.IsCancellationRequested &&
// This supplies the newline in the Legacy ReadLine when executing code in the terminal via hitting the ENTER key.
// Without this, hitting ENTER with a no input looks like it does nothing (no new prompt is written)
// and also the output would show up on the same line as the code you wanted to execute (the prompt line).
// Since PSReadLine handles ENTER internally to itself, we only want to do this when using the Legacy ReadLine.
if (!_isPSReadLineEnabled &&
!cancellationToken.IsCancellationRequested &&
originalCursorTop == await ConsoleProxy.GetCursorTopAsync(cancellationToken).ConfigureAwait(false))
{
this.WriteLine();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ public ProtocolPSHostUserInterface(
ILanguageServer languageServer,
PowerShellContextService powerShellContext,
ILogger logger)
: base(powerShellContext, new SimplePSHostRawUserInterface(logger), logger)
: base (
powerShellContext,
new SimplePSHostRawUserInterface(logger),
isPSReadLineEnabled: false,
logger)
{
_languageServer = languageServer;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ public class TerminalPSHostUserInterface : EditorServicesPSHostUserInterface
/// <param name="internalHost">The InternalHost instance from the origin runspace.</param>
public TerminalPSHostUserInterface(
PowerShellContextService powerShellContext,
ILogger logger,
PSHost internalHost)
: base(
PSHost internalHost,
bool isPSReadLineEnabled,
ILogger logger)
: base (
powerShellContext,
new TerminalPSHostRawUserInterface(logger, internalHost),
isPSReadLineEnabled,
logger)
{
this.internalHostUI = internalHost.UI;
Expand Down