@@ -33,10 +33,18 @@ namespace Microsoft.PowerShell.EditorServices.Services
33
33
/// </summary>
34
34
internal class PowerShellContextService : IHostSupportsInteractiveSession
35
35
{
36
- private static readonly string s_commandsModulePath = Path . GetFullPath (
37
- Path . Combine (
38
- Path . GetDirectoryName ( Assembly . GetExecutingAssembly ( ) . Location ) ,
39
- "../../Commands/PowerShellEditorServices.Commands.psd1" ) ) ;
36
+ // This is a default that can be overriden at runtime by the user or tests.
37
+ private static string s_bundledModulePath = Path . GetFullPath ( Path . Combine (
38
+ Path . GetDirectoryName ( typeof ( PowerShellContextService ) . Assembly . Location ) ,
39
+ ".." ,
40
+ ".." ,
41
+ ".." ) ) ;
42
+
43
+ private static string s_commandsModulePath => Path . GetFullPath ( Path . Combine (
44
+ s_bundledModulePath ,
45
+ "PowerShellEditorServices" ,
46
+ "Commands" ,
47
+ "PowerShellEditorServices.Commands.psd1" ) ) ;
40
48
41
49
private static readonly Action < Runspace , ApartmentState > s_runspaceApartmentStateSetter ;
42
50
private static readonly PropertyInfo s_writeStreamProperty ;
@@ -190,9 +198,16 @@ public static PowerShellContextService Create(
190
198
OmniSharp . Extensions . LanguageServer . Protocol . Server . ILanguageServerFacade languageServer ,
191
199
HostStartupInfo hostStartupInfo )
192
200
{
201
+ var logger = factory . CreateLogger < PowerShellContextService > ( ) ;
202
+
193
203
Validate . IsNotNull ( nameof ( hostStartupInfo ) , hostStartupInfo ) ;
194
204
195
- var logger = factory . CreateLogger < PowerShellContextService > ( ) ;
205
+ // Respect a user provided bundled module path.
206
+ if ( Directory . Exists ( hostStartupInfo . BundledModulePath ) )
207
+ {
208
+ logger . LogTrace ( $ "Using new bundled module path: { hostStartupInfo . BundledModulePath } ") ;
209
+ s_bundledModulePath = hostStartupInfo . BundledModulePath ;
210
+ }
196
211
197
212
bool shouldUsePSReadLine = hostStartupInfo . ConsoleReplEnabled
198
213
&& ! hostStartupInfo . UsesLegacyReadLine ;
@@ -404,7 +419,7 @@ public void Initialize(
404
419
405
420
if ( powerShellVersion . Major >= 5 &&
406
421
this . isPSReadLineEnabled &&
407
- PSReadLinePromptContext . TryGetPSReadLineProxy ( logger , initialRunspace , out PSReadLineProxy proxy ) )
422
+ PSReadLinePromptContext . TryGetPSReadLineProxy ( logger , initialRunspace , s_bundledModulePath , out PSReadLineProxy proxy ) )
408
423
{
409
424
this . PromptContext = new PSReadLinePromptContext (
410
425
this ,
@@ -423,15 +438,13 @@ public void Initialize(
423
438
/// the runspace. This method will be moved somewhere else soon.
424
439
/// </summary>
425
440
/// <returns></returns>
426
- public Task ImportCommandsModuleAsync ( ) => ImportCommandsModuleAsync ( s_commandsModulePath ) ;
427
-
428
- public Task ImportCommandsModuleAsync ( string path )
441
+ public Task ImportCommandsModuleAsync ( )
429
442
{
430
- this . logger . LogTrace ( $ "Importing PowershellEditorServices commands from { path } ") ;
443
+ this . logger . LogTrace ( $ "Importing PowershellEditorServices commands from { s_commandsModulePath } ") ;
431
444
432
445
PSCommand importCommand = new PSCommand ( )
433
446
. AddCommand ( "Import-Module" )
434
- . AddArgument ( path ) ;
447
+ . AddArgument ( s_commandsModulePath ) ;
435
448
436
449
return this . ExecuteCommandAsync < PSObject > ( importCommand , sendOutputToHost : false , sendErrorToHost : false ) ;
437
450
}
0 commit comments