Skip to content

Display prompt after F8 finishes #1690

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 3 commits 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
Expand Up @@ -47,10 +47,10 @@ public async Task<EvaluateResponseBody> Handle(EvaluateRequestArguments request,

if (isFromRepl)
{
_executionService.ExecutePSCommandAsync(
await _executionService.ExecutePSCommandAsync(
new PSCommand().AddScript(request.Expression),
CancellationToken.None,
new PowerShellExecutionOptions { WriteOutputToHost = true, ThrowOnError = false, AddToHistory = true }).HandleErrorsAsync(_logger);
new PowerShellExecutionOptions { WriteOutputToHost = true, ThrowOnError = false, AddToHistory = true }).HandleErrorsAsync(_logger).ConfigureAwait(false);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@ public TResult Result
throw new OperationCanceledException();
}

if (_exceptionInfo is not null)
{
_exceptionInfo.Throw();
}
_exceptionInfo?.Throw();

return _result;
}
Expand All @@ -79,27 +76,25 @@ public void ExecuteSynchronously(CancellationToken executorCancellationToken)
return;
}

using (var cancellationSource = CancellationTokenSource.CreateLinkedTokenSource(_taskRequesterCancellationToken, executorCancellationToken))
using var cancellationSource = CancellationTokenSource.CreateLinkedTokenSource(_taskRequesterCancellationToken, executorCancellationToken);
if (cancellationSource.IsCancellationRequested)
{
if (cancellationSource.IsCancellationRequested)
{
SetCanceled();
return;
}
SetCanceled();
return;
}

try
{
TResult result = Run(cancellationSource.Token);
SetResult(result);
}
catch (OperationCanceledException)
{
SetCanceled();
}
catch (Exception e)
{
SetException(e);
}
try
{
TResult result = Run(cancellationSource.Token);
SetResult(result);
}
catch (OperationCanceledException)
{
SetCanceled();
}
catch (Exception e)
{
SetException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,22 @@ public EvaluateHandler(
_executionService = executionService;
}

public Task<EvaluateResponseBody> Handle(EvaluateRequestArguments request, CancellationToken cancellationToken)
public async Task<EvaluateResponseBody> Handle(EvaluateRequestArguments request, CancellationToken cancellationToken)
{
// TODO: Understand why we currently handle this asynchronously and why we return a dummy result value
// instead of awaiting the execution and returing a real result of some kind

// This API is mostly used for F8 execution, so needs to interrupt the command prompt
_executionService.ExecutePSCommandAsync(
await _executionService.ExecutePSCommandAsync(
new PSCommand().AddScript(request.Expression),
CancellationToken.None,
new PowerShellExecutionOptions { WriteInputToHost = true, WriteOutputToHost = true, AddToHistory = true, ThrowOnError = false, InterruptCurrentForeground = true })
.HandleErrorsAsync(_logger);
new PowerShellExecutionOptions { WriteInputToHost = true, WriteOutputToHost = true, AddToHistory = true, ThrowOnError = false, InterruptCurrentForeground = true }).ConfigureAwait(false);

return Task.FromResult(new EvaluateResponseBody
return new EvaluateResponseBody
{
Result = "",
VariablesReference = 0
});
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,13 @@ public Task<T> InvokeTaskOnPipelineThreadAsync<T>(
// - block the consumer thread from mutating the queue
// - cancel any running task on the consumer thread
// - place our task on the front of the queue
// - skip the next prompt so the task runs instead
// - unblock the consumer thread
using (_taskQueue.BlockConsumers())
{
CancelCurrentTask();
_taskQueue.Prepend(task);
_skipNextPrompt = true;
}

return task.Task;
Expand Down