@@ -29,11 +29,11 @@ internal class PsesInternalHost : PSHost, IHostSupportsInteractiveSession, IRuns
29
29
{
30
30
private const string DefaultPrompt = "PSIC> " ;
31
31
// This is a default that can be overriden at runtime by the user or tests.
32
- private static string s_bundledModulePath = Path . GetFullPath ( Path . Combine (
32
+ private static string _bundledModulePath = Path . GetFullPath ( Path . Combine (
33
33
Path . GetDirectoryName ( typeof ( PsesInternalHost ) . Assembly . Location ) , ".." , ".." , ".." ) ) ;
34
34
35
- private static string s_commandsModulePath => Path . GetFullPath ( Path . Combine (
36
- s_bundledModulePath , "PowerShellEditorServices" , "Commands" , "PowerShellEditorServices.Commands.psd1" ) ) ;
35
+ private static string _commandsModulePath => Path . GetFullPath ( Path . Combine (
36
+ _bundledModulePath , "PowerShellEditorServices" , "Commands" , "PowerShellEditorServices.Commands.psd1" ) ) ;
37
37
38
38
private readonly ILoggerFactory _loggerFactory ;
39
39
@@ -89,7 +89,7 @@ public PsesInternalHost(
89
89
if ( Directory . Exists ( hostInfo . BundledModulePath ) )
90
90
{
91
91
_logger . LogTrace ( "Using new bundled module path: {}" , hostInfo . BundledModulePath ) ;
92
- s_bundledModulePath = hostInfo . BundledModulePath ;
92
+ _bundledModulePath = hostInfo . BundledModulePath ;
93
93
}
94
94
95
95
_readLineProvider = new ReadLineProvider ( loggerFactory ) ;
@@ -216,12 +216,7 @@ public async Task<bool> TryStartAsync(HostStartOptions startOptions, Cancellatio
216
216
217
217
if ( startOptions . LoadProfiles )
218
218
{
219
- await ExecuteDelegateAsync (
220
- "LoadProfiles" ,
221
- new PowerShellExecutionOptions { MustRunInForeground = true , ThrowOnError = false } ,
222
- ( pwsh , _ ) => pwsh . LoadProfiles ( _hostInfo . ProfilePaths ) ,
223
- cancellationToken ) . ConfigureAwait ( false ) ;
224
-
219
+ await LoadHostProfilesAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
225
220
_logger . LogInformation ( "Profiles loaded" ) ;
226
221
}
227
222
@@ -391,6 +386,15 @@ public void InvokePSDelegate(string representation, ExecutionOptions executionOp
391
386
task . ExecuteAndGetResult ( cancellationToken ) ;
392
387
}
393
388
389
+ internal Task LoadHostProfilesAsync ( CancellationToken cancellationToken )
390
+ {
391
+ return ExecuteDelegateAsync (
392
+ "LoadProfiles" ,
393
+ new PowerShellExecutionOptions { MustRunInForeground = true , ThrowOnError = false } ,
394
+ ( pwsh , _ ) => pwsh . LoadProfiles ( _hostInfo . ProfilePaths ) ,
395
+ cancellationToken ) ;
396
+ }
397
+
394
398
public Task SetInitialWorkingDirectoryAsync ( string path , CancellationToken cancellationToken )
395
399
{
396
400
InitialWorkingDirectory = path ;
@@ -738,7 +742,7 @@ private static PowerShell CreatePowerShellForRunspace(Runspace runspace)
738
742
pwsh . SetCorrectExecutionPolicy ( _logger ) ;
739
743
}
740
744
741
- pwsh . ImportModule ( s_commandsModulePath ) ;
745
+ pwsh . ImportModule ( _commandsModulePath ) ;
742
746
743
747
if ( hostStartupInfo . AdditionalModules ? . Count > 0 )
744
748
{
@@ -919,12 +923,12 @@ private Task PopOrReinitializeRunspaceAsync()
919
923
CancellationToken . None ) ;
920
924
}
921
925
922
- private bool TryLoadPSReadLine ( PowerShell pwsh , EngineIntrinsics engineIntrinsics , out IReadLine psrlReadLine )
926
+ internal bool TryLoadPSReadLine ( PowerShell pwsh , EngineIntrinsics engineIntrinsics , out IReadLine psrlReadLine )
923
927
{
924
928
psrlReadLine = null ;
925
929
try
926
930
{
927
- var psrlProxy = PSReadLineProxy . LoadAndCreate ( _loggerFactory , s_bundledModulePath , pwsh ) ;
931
+ var psrlProxy = PSReadLineProxy . LoadAndCreate ( _loggerFactory , _bundledModulePath , pwsh ) ;
928
932
psrlReadLine = new PsrlReadLine ( psrlProxy , this , engineIntrinsics , ReadKey , OnPowerShellIdle ) ;
929
933
return true ;
930
934
}
0 commit comments