Skip to content

Commit 2621e13

Browse files
Merge pull request #1762 from SeeminglyScience/more-debug-changes
Fix prompt spam and general debugger reliability improvements
2 parents a62d6bc + 1376621 commit 2621e13

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ private void StopDebuggerIfRemoteDebugSessionFailed()
333333

334334
private void CancelNormalExecution()
335335
{
336-
if (_pwsh.Runspace.RunspaceStateInfo.IsUsable())
336+
if (!_pwsh.Runspace.RunspaceStateInfo.IsUsable())
337337
{
338338
return;
339339
}

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

+20-7
Original file line numberDiff line numberDiff line change
@@ -680,18 +680,30 @@ private void RunExecutionLoop(bool isForDebug = false)
680680
}
681681

682682
using CancellationScope cancellationScope = _cancellationContext.EnterScope(false);
683-
DoOneRepl(cancellationScope.CancellationToken);
683+
684+
try
685+
{
686+
DoOneRepl(cancellationScope.CancellationToken);
687+
}
688+
catch (OperationCanceledException)
689+
{
690+
if (isForDebug)
691+
{
692+
while (Runspace is { RunspaceIsRemote: true } remoteRunspace
693+
&& !remoteRunspace.RunspaceStateInfo.IsUsable())
694+
{
695+
PopPowerShell(RunspaceChangeAction.Exit);
696+
}
697+
698+
return;
699+
}
700+
}
684701

685702
while (!ShouldExitExecutionLoop
686703
&& !cancellationScope.CancellationToken.IsCancellationRequested
687704
&& _taskQueue.TryTake(out ISynchronousTask task))
688705
{
689706
task.ExecuteSynchronously(cancellationScope.CancellationToken);
690-
while (Runspace is { RunspaceIsRemote: true } remoteRunspace
691-
&& !remoteRunspace.RunspaceStateInfo.IsUsable())
692-
{
693-
PopPowerShell(RunspaceChangeAction.Exit);
694-
}
695707
}
696708

697709
if (_shouldExit
@@ -759,7 +771,7 @@ private void DoOneRepl(CancellationToken cancellationToken)
759771
}
760772
catch (OperationCanceledException)
761773
{
762-
// Do nothing, since we were just cancelled
774+
throw;
763775
}
764776
// Propagate exceptions thrown from the debugger when quitting.
765777
catch (TerminateException)
@@ -828,6 +840,7 @@ public void WriteWithPrompt(PSCommand command, CancellationToken cancellationTok
828840

829841
private string InvokeReadLine(CancellationToken cancellationToken)
830842
{
843+
cancellationToken.ThrowIfCancellationRequested();
831844
try
832845
{
833846
_readKeyCancellationToken = cancellationToken;

0 commit comments

Comments
 (0)