1
- // Copyright (c) Microsoft Corporation.
1
+ // Copyright (c) Microsoft Corporation.
2
2
// Licensed under the MIT License.
3
3
4
4
using System ;
@@ -277,6 +277,8 @@ public void SetExit()
277
277
public Task < T > InvokeTaskOnPipelineThreadAsync < T > (
278
278
SynchronousTask < T > task )
279
279
{
280
+ // NOTE: This causes foreground tasks to act like they have `ExecutionPriority.Next`.
281
+ // TODO: Deduplicate this.
280
282
if ( task . ExecutionOptions . RequiresForeground )
281
283
{
282
284
// When a task must displace the current foreground command,
@@ -296,6 +298,7 @@ public Task<T> InvokeTaskOnPipelineThreadAsync<T>(
296
298
return task . Task ;
297
299
}
298
300
301
+ // TODO: Apply stashed `QueueTask` function.
299
302
switch ( task . ExecutionOptions . Priority )
300
303
{
301
304
case ExecutionPriority . Next :
@@ -404,14 +407,10 @@ public void InvokePSDelegate(string representation, ExecutionOptions executionOp
404
407
405
408
internal Task LoadHostProfilesAsync ( CancellationToken cancellationToken )
406
409
{
407
- // TODO: Why exactly does loading profiles require the foreground?
410
+ // NOTE: This is a special task run on startup!
408
411
return ExecuteDelegateAsync (
409
412
"LoadProfiles" ,
410
- new PowerShellExecutionOptions
411
- {
412
- RequiresForeground = true ,
413
- ThrowOnError = false
414
- } ,
413
+ new PowerShellExecutionOptions { ThrowOnError = false } ,
415
414
( pwsh , _ ) => pwsh . LoadProfiles ( _hostInfo . ProfilePaths ) ,
416
415
cancellationToken ) ;
417
416
}
@@ -625,7 +624,10 @@ private void RunTopLevelExecutionLoop()
625
624
{
626
625
try
627
626
{
628
- // Make sure we execute any startup tasks first
627
+ // Make sure we execute any startup tasks first. These should be, in order:
628
+ // 1. Delegate to register psEditor variable
629
+ // 2. LoadProfiles delegate
630
+ // 3. Delegate to import PSEditModule
629
631
while ( _taskQueue . TryTake ( out ISynchronousTask task ) )
630
632
{
631
633
task . ExecuteSynchronously ( CancellationToken . None ) ;
@@ -1003,6 +1005,8 @@ private void OnPowerShellIdle(CancellationToken idleCancellationToken)
1003
1005
while ( ! cancellationScope . CancellationToken . IsCancellationRequested
1004
1006
&& _taskQueue . TryTake ( out ISynchronousTask task ) )
1005
1007
{
1008
+ // NOTE: This causes foreground tasks to act like they have `ExecutionPriority.Next`.
1009
+ // TODO: Deduplicate this.
1006
1010
if ( task . ExecutionOptions . RequiresForeground )
1007
1011
{
1008
1012
// If we have a task that is queued, but cannot be run under readline
0 commit comments