1
1
// Copyright (c) Microsoft Corporation.
2
2
// Licensed under the MIT License.
3
3
4
- using Microsoft . Extensions . Logging ;
5
- using Microsoft . PowerShell . EditorServices . Hosting ;
6
- using Microsoft . PowerShell . EditorServices . Services . PowerShell . Console ;
7
- using Microsoft . PowerShell . EditorServices . Services . PowerShell . Context ;
8
- using Microsoft . PowerShell . EditorServices . Services . PowerShell . Runspace ;
9
- using OmniSharp . Extensions . LanguageServer . Protocol . Server ;
10
4
using System ;
11
5
using System . Collections . Generic ;
12
6
using System . Globalization ;
7
+ using System . IO ;
13
8
using System . Management . Automation . Host ;
9
+ using System . Text ;
10
+ using System . Threading ;
11
+ using System . Threading . Tasks ;
12
+ using Microsoft . Extensions . Logging ;
13
+ using Microsoft . PowerShell . EditorServices . Hosting ;
14
+ using Microsoft . PowerShell . EditorServices . Services . PowerShell . Console ;
15
+ using Microsoft . PowerShell . EditorServices . Services . PowerShell . Context ;
14
16
using Microsoft . PowerShell . EditorServices . Services . PowerShell . Debugging ;
15
17
using Microsoft . PowerShell . EditorServices . Services . PowerShell . Execution ;
18
+ using Microsoft . PowerShell . EditorServices . Services . PowerShell . Runspace ;
16
19
using Microsoft . PowerShell . EditorServices . Services . PowerShell . Utility ;
17
20
using Microsoft . PowerShell . EditorServices . Utility ;
18
- using System . IO ;
19
- using System . Reflection ;
20
- using System . Text ;
21
- using System . Threading ;
22
- using System . Threading . Tasks ;
21
+ using OmniSharp . Extensions . LanguageServer . Protocol . Server ;
23
22
24
23
namespace Microsoft . PowerShell . EditorServices . Services . PowerShell . Host
25
24
{
@@ -29,11 +28,12 @@ namespace Microsoft.PowerShell.EditorServices.Services.PowerShell.Host
29
28
internal class PsesInternalHost : PSHost , IHostSupportsInteractiveSession , IRunspaceContext , IInternalPowerShellExecutionService
30
29
{
31
30
private const string DefaultPrompt = "PSIC> " ;
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 (
33
+ Path . GetDirectoryName ( typeof ( PsesInternalHost ) . Assembly . Location ) , ".." , ".." , ".." ) ) ;
32
34
33
- private static readonly string s_commandsModulePath = Path . GetFullPath (
34
- Path . Combine (
35
- Path . GetDirectoryName ( Assembly . GetExecutingAssembly ( ) . Location ) ,
36
- "../../Commands/PowerShellEditorServices.Commands.psd1" ) ) ;
35
+ private static string s_commandsModulePath => Path . GetFullPath ( Path . Combine (
36
+ s_bundledModulePath , "PowerShellEditorServices" , "Commands" , "PowerShellEditorServices.Commands.psd1" ) ) ;
37
37
38
38
private readonly ILoggerFactory _loggerFactory ;
39
39
@@ -85,6 +85,13 @@ public PsesInternalHost(
85
85
_languageServer = languageServer ;
86
86
_hostInfo = hostInfo ;
87
87
88
+ // Respect a user provided bundled module path.
89
+ if ( Directory . Exists ( hostInfo . BundledModulePath ) )
90
+ {
91
+ _logger . LogTrace ( "Using new bundled module path: {}" , hostInfo . BundledModulePath ) ;
92
+ s_bundledModulePath = hostInfo . BundledModulePath ;
93
+ }
94
+
88
95
_readLineProvider = new ReadLineProvider ( loggerFactory ) ;
89
96
_taskQueue = new BlockingConcurrentDeque < ISynchronousTask > ( ) ;
90
97
_psFrameStack = new Stack < PowerShellContextFrame > ( ) ;
@@ -212,7 +219,7 @@ public async Task<bool> TryStartAsync(HostStartOptions startOptions, Cancellatio
212
219
await ExecuteDelegateAsync (
213
220
"LoadProfiles" ,
214
221
new PowerShellExecutionOptions { MustRunInForeground = true , ThrowOnError = false } ,
215
- ( pwsh , delegateCancellation ) => pwsh . LoadProfiles ( _hostInfo . ProfilePaths ) ,
222
+ ( pwsh , _ ) => pwsh . LoadProfiles ( _hostInfo . ProfilePaths ) ,
216
223
cancellationToken ) . ConfigureAwait ( false ) ;
217
224
218
225
_logger . LogInformation ( "Profiles loaded" ) ;
@@ -747,7 +754,7 @@ private static PowerShell CreatePowerShellForRunspace(Runspace runspace)
747
754
748
755
pwsh . ImportModule ( s_commandsModulePath ) ;
749
756
750
- if ( hostStartupInfo . AdditionalModules != null && hostStartupInfo . AdditionalModules . Count > 0 )
757
+ if ( hostStartupInfo . AdditionalModules ? . Count > 0 )
751
758
{
752
759
foreach ( string module in hostStartupInfo . AdditionalModules )
753
760
{
@@ -931,7 +938,7 @@ private bool TryLoadPSReadLine(PowerShell pwsh, EngineIntrinsics engineIntrinsic
931
938
psrlReadLine = null ;
932
939
try
933
940
{
934
- var psrlProxy = PSReadLineProxy . LoadAndCreate ( _loggerFactory , pwsh ) ;
941
+ var psrlProxy = PSReadLineProxy . LoadAndCreate ( _loggerFactory , s_bundledModulePath , pwsh ) ;
935
942
psrlReadLine = new PsrlReadLine ( psrlProxy , this , engineIntrinsics , ReadKey , OnPowerShellIdle ) ;
936
943
return true ;
937
944
}
0 commit comments