Skip to content

Commit 8108224

Browse files
committed
Convert PSRL OnIdle handler to take a CancellationToken
1 parent 7ed4903 commit 8108224

File tree

5 files changed

+11
-9
lines changed

5 files changed

+11
-9
lines changed

src/PowerShellEditorServices/Services/PowerShell/Console/ConsoleReadLine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public bool TryOverrideReadKey(Func<bool, ConsoleKeyInfo> readKeyFunc)
4949
return true;
5050
}
5151

52-
public bool TryOverrideIdleHandler(Action idleHandler)
52+
public bool TryOverrideIdleHandler(Action<CancellationToken> idleHandler)
5353
{
5454
_psrlProxy.OverrideIdleHandler(idleHandler);
5555
return true;

src/PowerShellEditorServices/Services/PowerShell/Console/IReadLine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ internal interface IReadLine
1515

1616
bool TryOverrideReadKey(Func<bool, ConsoleKeyInfo> readKeyOverride);
1717

18-
bool TryOverrideIdleHandler(Action idleHandler);
18+
bool TryOverrideIdleHandler(Action<CancellationToken> idleHandler);
1919
}
2020
}

src/PowerShellEditorServices/Services/PowerShell/Console/PSReadLineProxy.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ internal void OverrideReadKey(Func<bool, ConsoleKeyInfo> readKeyFunc)
168168
_readKeyOverrideField.SetValue(null, readKeyFunc);
169169
}
170170

171-
internal void OverrideIdleHandler(Action idleAction)
171+
internal void OverrideIdleHandler(Action<CancellationToken> idleAction)
172172
{
173173
_handleIdleOverrideField.SetValue(null, idleAction);
174174
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ private static PowerShell CreatePowerShellForRunspace(Runspace runspace)
616616
return pwsh;
617617
}
618618

619-
public (PowerShell, EngineIntrinsics) CreateInitialPowerShell(
619+
private (PowerShell, EngineIntrinsics) CreateInitialPowerShell(
620620
HostStartupInfo hostStartupInfo,
621621
ReadLineProvider readLineProvider)
622622
{
@@ -669,7 +669,7 @@ private Runspace CreateInitialRunspace(InitialSessionState initialSessionState)
669669
return runspace;
670670
}
671671

672-
private void OnPowerShellIdle()
672+
private void OnPowerShellIdle(CancellationToken idleCancellationToken)
673673
{
674674
IReadOnlyList<PSEventSubscriber> eventSubscribers = _mainRunspaceEngineIntrinsics.Events.Subscribers;
675675

@@ -696,7 +696,7 @@ private void OnPowerShellIdle()
696696
return;
697697
}
698698

699-
using (CancellationScope cancellationScope = _cancellationContext.EnterScope(isIdleScope: true))
699+
using (CancellationScope cancellationScope = _cancellationContext.EnterScope(isIdleScope: true, idleCancellationToken))
700700
{
701701
while (!cancellationScope.CancellationToken.IsCancellationRequested
702702
&& _taskQueue.TryTake(out ISynchronousTask task))

src/PowerShellEditorServices/Services/PowerShell/Utility/CancellationContext.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,17 @@ public CancellationContext()
3333
_cancellationSourceStack = new ConcurrentStack<CancellationScope>();
3434
}
3535

36-
public CancellationScope EnterScope(bool isIdleScope)
36+
public CancellationScope EnterScope(bool isIdleScope, CancellationToken cancellationToken)
3737
{
3838
CancellationTokenSource newScopeCancellationSource = _cancellationSourceStack.TryPeek(out CancellationScope parentScope)
39-
? CancellationTokenSource.CreateLinkedTokenSource(parentScope.CancellationToken)
40-
: new CancellationTokenSource();
39+
? CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, parentScope.CancellationToken)
40+
: CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
4141

4242
return EnterScope(isIdleScope, newScopeCancellationSource);
4343
}
4444

45+
public CancellationScope EnterScope(bool isIdleScope) => EnterScope(isIdleScope, CancellationToken.None);
46+
4547
public void CancelCurrentTask()
4648
{
4749
if (_cancellationSourceStack.TryPeek(out CancellationScope currentCancellationSource))

0 commit comments

Comments
 (0)