@@ -24,16 +24,6 @@ internal class PSReadLinePromptContext : IPromptContext
24
24
".." ,
25
25
"PSReadLine" ) ;
26
26
27
- // TODO: Does this have to be done in an inline script?
28
- private static readonly string ReadLineInitScript = $@ "
29
- [System.Diagnostics.DebuggerHidden()]
30
- [System.Diagnostics.DebuggerStepThrough()]
31
- param()
32
- end {{
33
- Import-Module '{ _psReadLineModulePath . Replace ( "'" , "''" ) } '
34
- return [Microsoft.PowerShell.PSConsoleReadLine]
35
- }}" ;
36
-
37
27
private static readonly Lazy < CmdletInfo > s_lazyInvokeReadLineForEditorServicesCmdletInfo = new Lazy < CmdletInfo > ( ( ) =>
38
28
{
39
29
var type = Type . GetType ( "Microsoft.PowerShell.EditorServices.Commands.InvokeReadLineForEditorServicesCommand, Microsoft.PowerShell.EditorServices.Hosting" ) ;
@@ -89,14 +79,15 @@ internal static bool TryGetPSReadLineProxy(
89
79
using ( var pwsh = PowerShell . Create ( ) )
90
80
{
91
81
pwsh . Runspace = runspace ;
92
- var psReadLineType = pwsh
93
- . AddScript ( ReadLineInitScript , useLocalScope : true )
94
- . Invoke < Type > ( )
95
- . FirstOrDefault ( ) ;
82
+ pwsh . AddCommand ( "Microsoft.PowerShell.Core\\ Import-Module" )
83
+ . AddParameter ( "Name" , _psReadLineModulePath )
84
+ . Invoke ( ) ;
85
+
86
+ var psReadLineType = Type . GetType ( "Microsoft.PowerShell.PSConsoleReadLine, Microsoft.PowerShell.PSReadLine2" ) ;
96
87
97
88
if ( psReadLineType == null )
98
89
{
99
- logger . LogWarning ( "PSReadLine unable to be loaded : {Reason}" , pwsh . HadErrors ? pwsh . Streams . Error [ 0 ] . ToString ( ) : "<Unknown reason>" ) ;
90
+ logger . LogWarning ( "PSConsoleReadline type not found : {Reason}" , pwsh . HadErrors ? pwsh . Streams . Error [ 0 ] . ToString ( ) : "<Unknown reason>" ) ;
100
91
return false ;
101
92
}
102
93
@@ -109,7 +100,7 @@ internal static bool TryGetPSReadLineProxy(
109
100
// The Type we got back from PowerShell doesn't have the members we expected.
110
101
// Could be an older version, a custom build, or something a newer version with
111
102
// breaking changes.
112
- logger . LogWarning ( "PSReadLine unable to be loaded : {Reason}" , e ) ;
103
+ logger . LogWarning ( "PSReadLineProxy unable to be initialized : {Reason}" , e ) ;
113
104
return false ;
114
105
}
115
106
}
0 commit comments