Skip to content

Commit 95715ed

Browse files
committed
Hide artificial pipeline from debugger
Same fix as applied in PowerShell/PSReadLine#3629
1 parent 6dca0bd commit 95715ed

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,7 +1207,18 @@ private Runspace CreateInitialRunspace(InitialSessionState initialSessionState)
12071207
return runspace;
12081208
}
12091209

1210-
// NOTE: This token is received from PSReadLine, and it _is_ the ReadKey cancellation token!
1210+
/// <summary>
1211+
/// This delegate is handed to PSReadLine and overrides similar logic within its `ReadKey`
1212+
/// method. Essentially we're replacing PowerShell's `OnIdle` handler since the PowerShell
1213+
/// engine isn't idle when we're sitting in PSReadLine's `ReadKey` loop. In our case we also
1214+
/// use this idle time to process queued tasks by executing those that can run in the
1215+
/// background, and canceling the foreground task if a queued tasks requires the foreground.
1216+
/// Finally, if and only if we have to, we run an artificial pipeline to force PowerShell's
1217+
/// own event processing.
1218+
/// </summary>
1219+
/// <param name="idleCancellationToken">
1220+
/// This token is received from PSReadLine, and it is the ReadKey cancellation token!
1221+
/// </param>
12111222
internal void OnPowerShellIdle(CancellationToken idleCancellationToken)
12121223
{
12131224
IReadOnlyList<PSEventSubscriber> eventSubscribers = _mainRunspaceEngineIntrinsics.Events.Subscribers;
@@ -1257,10 +1268,15 @@ internal void OnPowerShellIdle(CancellationToken idleCancellationToken)
12571268

12581269
// We didn't end up executing anything in the background,
12591270
// so we need to run a small artificial pipeline instead
1260-
// to force event processing
1271+
// to force event processing.
12611272
if (runPipelineForEventProcessing)
12621273
{
1263-
InvokePSCommand(new PSCommand().AddScript("0", useLocalScope: true), executionOptions: null, CancellationToken.None);
1274+
InvokePSCommand(
1275+
new PSCommand().AddScript(
1276+
"[System.Diagnostics.DebuggerHidden()]param() 0",
1277+
useLocalScope: true),
1278+
executionOptions: null,
1279+
CancellationToken.None);
12641280
}
12651281
}
12661282

0 commit comments

Comments
 (0)