Skip to content

Commit f3cea93

Browse files
Merge pull request #1690 from PowerShell/andschwa/fix-prompting
Display prompt after `F8` finishes
2 parents f890a75 + 940ca43 commit f3cea93

File tree

4 files changed

+27
-31
lines changed

4 files changed

+27
-31
lines changed

src/PowerShellEditorServices/Services/DebugAdapter/Handlers/DebugEvaluateHandler.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ public async Task<EvaluateResponseBody> Handle(EvaluateRequestArguments request,
4747

4848
if (isFromRepl)
4949
{
50-
_executionService.ExecutePSCommandAsync(
50+
await _executionService.ExecutePSCommandAsync(
5151
new PSCommand().AddScript(request.Expression),
5252
CancellationToken.None,
53-
new PowerShellExecutionOptions { WriteOutputToHost = true, ThrowOnError = false, AddToHistory = true }).HandleErrorsAsync(_logger);
53+
new PowerShellExecutionOptions { WriteOutputToHost = true, ThrowOnError = false, AddToHistory = true }).HandleErrorsAsync(_logger).ConfigureAwait(false);
5454
}
5555
else
5656
{

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

+18-23
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,7 @@ public TResult Result
5555
throw new OperationCanceledException();
5656
}
5757

58-
if (_exceptionInfo is not null)
59-
{
60-
_exceptionInfo.Throw();
61-
}
58+
_exceptionInfo?.Throw();
6259

6360
return _result;
6461
}
@@ -79,27 +76,25 @@ public void ExecuteSynchronously(CancellationToken executorCancellationToken)
7976
return;
8077
}
8178

82-
using (var cancellationSource = CancellationTokenSource.CreateLinkedTokenSource(_taskRequesterCancellationToken, executorCancellationToken))
79+
using var cancellationSource = CancellationTokenSource.CreateLinkedTokenSource(_taskRequesterCancellationToken, executorCancellationToken);
80+
if (cancellationSource.IsCancellationRequested)
8381
{
84-
if (cancellationSource.IsCancellationRequested)
85-
{
86-
SetCanceled();
87-
return;
88-
}
82+
SetCanceled();
83+
return;
84+
}
8985

90-
try
91-
{
92-
TResult result = Run(cancellationSource.Token);
93-
SetResult(result);
94-
}
95-
catch (OperationCanceledException)
96-
{
97-
SetCanceled();
98-
}
99-
catch (Exception e)
100-
{
101-
SetException(e);
102-
}
86+
try
87+
{
88+
TResult result = Run(cancellationSource.Token);
89+
SetResult(result);
90+
}
91+
catch (OperationCanceledException)
92+
{
93+
SetCanceled();
94+
}
95+
catch (Exception e)
96+
{
97+
SetException(e);
10398
}
10499
}
105100

src/PowerShellEditorServices/Services/PowerShell/Handlers/EvaluateHandler.cs

+5-6
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,22 @@ public EvaluateHandler(
2828
_executionService = executionService;
2929
}
3030

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

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

43-
return Task.FromResult(new EvaluateResponseBody
42+
return new EvaluateResponseBody
4443
{
4544
Result = "",
4645
VariablesReference = 0
47-
});
46+
};
4847
}
4948
}
5049
}

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

+2
Original file line numberDiff line numberDiff line change
@@ -270,11 +270,13 @@ public Task<T> InvokeTaskOnPipelineThreadAsync<T>(
270270
// - block the consumer thread from mutating the queue
271271
// - cancel any running task on the consumer thread
272272
// - place our task on the front of the queue
273+
// - skip the next prompt so the task runs instead
273274
// - unblock the consumer thread
274275
using (_taskQueue.BlockConsumers())
275276
{
276277
CancelCurrentTask();
277278
_taskQueue.Prepend(task);
279+
_skipNextPrompt = true;
278280
}
279281

280282
return task.Task;

0 commit comments

Comments
 (0)