1
- // Copyright (c) Microsoft Corporation.
1
+ // Copyright (c) Microsoft Corporation.
2
2
// Licensed under the MIT License.
3
3
4
4
using System ;
@@ -277,7 +277,7 @@ public void SetExit()
277
277
public Task < T > InvokeTaskOnPipelineThreadAsync < T > (
278
278
SynchronousTask < T > task )
279
279
{
280
- if ( task . ExecutionOptions . RequiresForeground )
280
+ if ( task . ExecutionOptions . InterruptCurrentForeground )
281
281
{
282
282
// When a task must displace the current foreground command,
283
283
// we must:
@@ -404,14 +404,9 @@ public void InvokePSDelegate(string representation, ExecutionOptions executionOp
404
404
405
405
internal Task LoadHostProfilesAsync ( CancellationToken cancellationToken )
406
406
{
407
- // TODO: Why exactly does loading profiles require the foreground?
408
407
return ExecuteDelegateAsync (
409
408
"LoadProfiles" ,
410
- new PowerShellExecutionOptions
411
- {
412
- RequiresForeground = true ,
413
- ThrowOnError = false
414
- } ,
409
+ new PowerShellExecutionOptions { MustRunInForeground = true , ThrowOnError = false } ,
415
410
( pwsh , _ ) => pwsh . LoadProfiles ( _hostInfo . ProfilePaths ) ,
416
411
cancellationToken ) ;
417
412
}
@@ -855,15 +850,7 @@ private string InvokeReadLine(CancellationToken cancellationToken)
855
850
private void InvokeInput ( string input , CancellationToken cancellationToken )
856
851
{
857
852
PSCommand command = new PSCommand ( ) . AddScript ( input , useLocalScope : false ) ;
858
- InvokePSCommand (
859
- command ,
860
- new PowerShellExecutionOptions
861
- {
862
- AddToHistory = true ,
863
- ThrowOnError = false ,
864
- WriteOutputToHost = true
865
- } ,
866
- cancellationToken ) ;
853
+ InvokePSCommand ( command , new PowerShellExecutionOptions { AddToHistory = true , ThrowOnError = false , WriteOutputToHost = true } , cancellationToken ) ;
867
854
}
868
855
869
856
private void AddRunspaceEventHandlers ( Runspace runspace )
@@ -957,7 +944,6 @@ private Runspace CreateInitialRunspace(InitialSessionState initialSessionState)
957
944
return runspace ;
958
945
}
959
946
960
- // NOTE: This token is received from PSReadLine, and it _is_ the ReadKey cancellation token!
961
947
private void OnPowerShellIdle ( CancellationToken idleCancellationToken )
962
948
{
963
949
IReadOnlyList < PSEventSubscriber > eventSubscribers = _mainRunspaceEngineIntrinsics . Events . Subscribers ;
@@ -990,7 +976,7 @@ private void OnPowerShellIdle(CancellationToken idleCancellationToken)
990
976
while ( ! cancellationScope . CancellationToken . IsCancellationRequested
991
977
&& _taskQueue . TryTake ( out ISynchronousTask task ) )
992
978
{
993
- if ( task . ExecutionOptions . RequiresForeground )
979
+ if ( task . ExecutionOptions . MustRunInForeground )
994
980
{
995
981
// If we have a task that is queued, but cannot be run under readline
996
982
// we place it back at the front of the queue, and cancel the readline task
@@ -1111,27 +1097,27 @@ private void OnDebuggerStopped(object sender, DebuggerStopEventArgs debuggerStop
1111
1097
1112
1098
void OnDebuggerStoppedImpl ( object sender , DebuggerStopEventArgs debuggerStopEventArgs )
1113
1099
{
1114
- // If the debug server is NOT active, we need to synchronize state and start it.
1115
- if ( ! DebugContext . IsDebugServerActive )
1116
- {
1117
- _languageServer ? . SendNotification ( "powerShell/startDebugger" ) ;
1118
- }
1100
+ // If the debug server is NOT active, we need to synchronize state and start it.
1101
+ if ( ! DebugContext . IsDebugServerActive )
1102
+ {
1103
+ _languageServer ? . SendNotification ( "powerShell/startDebugger" ) ;
1104
+ }
1119
1105
1120
- DebugContext . SetDebuggerStopped ( debuggerStopEventArgs ) ;
1106
+ DebugContext . SetDebuggerStopped ( debuggerStopEventArgs ) ;
1121
1107
1122
- try
1123
- {
1124
- CurrentPowerShell . WaitForRemoteOutputIfNeeded ( ) ;
1125
- PowerShellFrameType frameBase = CurrentFrame . FrameType & PowerShellFrameType . Remote ;
1126
- PushPowerShellAndRunLoop (
1127
- CreateNestedPowerShell ( CurrentRunspace ) ,
1128
- frameBase | PowerShellFrameType . Debug | PowerShellFrameType . Nested | PowerShellFrameType . Repl ) ;
1129
- CurrentPowerShell . ResumeRemoteOutputIfNeeded ( ) ;
1130
- }
1131
- finally
1132
- {
1133
- DebugContext . SetDebuggerResumed ( ) ;
1134
- }
1108
+ try
1109
+ {
1110
+ CurrentPowerShell . WaitForRemoteOutputIfNeeded ( ) ;
1111
+ PowerShellFrameType frameBase = CurrentFrame . FrameType & PowerShellFrameType . Remote ;
1112
+ PushPowerShellAndRunLoop (
1113
+ CreateNestedPowerShell ( CurrentRunspace ) ,
1114
+ frameBase | PowerShellFrameType . Debug | PowerShellFrameType . Nested | PowerShellFrameType . Repl ) ;
1115
+ CurrentPowerShell . ResumeRemoteOutputIfNeeded ( ) ;
1116
+ }
1117
+ finally
1118
+ {
1119
+ DebugContext . SetDebuggerResumed ( ) ;
1120
+ }
1135
1121
}
1136
1122
}
1137
1123
@@ -1155,7 +1141,7 @@ private Task PopOrReinitializeRunspaceAsync()
1155
1141
// we simply run this on its thread, guaranteeing that no other action can occur
1156
1142
return ExecuteDelegateAsync (
1157
1143
nameof ( PopOrReinitializeRunspaceAsync ) ,
1158
- new ExecutionOptions { RequiresForeground = true } ,
1144
+ new ExecutionOptions { InterruptCurrentForeground = true } ,
1159
1145
( _ ) =>
1160
1146
{
1161
1147
while ( _psFrameStack . Count > 0
0 commit comments