@@ -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 ;
@@ -406,7 +421,7 @@ public void Initialize(
406
421
407
422
if ( powerShellVersion . Major >= 5 &&
408
423
this . isPSReadLineEnabled &&
409
- PSReadLinePromptContext . TryGetPSReadLineProxy ( logger , initialRunspace , out PSReadLineProxy proxy ) )
424
+ PSReadLinePromptContext . TryGetPSReadLineProxy ( logger , initialRunspace , s_bundledModulePath , out PSReadLineProxy proxy ) )
410
425
{
411
426
this . PromptContext = new PSReadLinePromptContext (
412
427
this ,
@@ -430,15 +445,13 @@ public void Initialize(
430
445
/// the runspace. This method will be moved somewhere else soon.
431
446
/// </summary>
432
447
/// <returns></returns>
433
- public Task ImportCommandsModuleAsync ( ) => ImportCommandsModuleAsync ( s_commandsModulePath ) ;
434
-
435
- public Task ImportCommandsModuleAsync ( string path )
448
+ public Task ImportCommandsModuleAsync ( )
436
449
{
437
- this . logger . LogTrace ( $ "Importing PowershellEditorServices commands from { path } ") ;
450
+ this . logger . LogTrace ( $ "Importing PowershellEditorServices commands from { s_commandsModulePath } ") ;
438
451
439
452
PSCommand importCommand = new PSCommand ( )
440
453
. AddCommand ( "Import-Module" )
441
- . AddArgument ( path ) ;
454
+ . AddArgument ( s_commandsModulePath ) ;
442
455
443
456
return this . ExecuteCommandAsync < PSObject > ( importCommand , sendOutputToHost : false , sendErrorToHost : false ) ;
444
457
}
0 commit comments