@@ -24,16 +24,6 @@ internal class PSReadLinePromptContext : IPromptContext
2424 ".." ,
2525 "PSReadLine" ) ;
2626
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-
3727 private static readonly Lazy < CmdletInfo > s_lazyInvokeReadLineForEditorServicesCmdletInfo = new Lazy < CmdletInfo > ( ( ) =>
3828 {
3929 var type = Type . GetType ( "Microsoft.PowerShell.EditorServices.Commands.InvokeReadLineForEditorServicesCommand, Microsoft.PowerShell.EditorServices.Hosting" ) ;
@@ -89,14 +79,15 @@ internal static bool TryGetPSReadLineProxy(
8979 using ( var pwsh = PowerShell . Create ( ) )
9080 {
9181 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" ) ;
9687
9788 if ( psReadLineType == null )
9889 {
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>" ) ;
10091 return false ;
10192 }
10293
@@ -109,7 +100,7 @@ internal static bool TryGetPSReadLineProxy(
109100 // The Type we got back from PowerShell doesn't have the members we expected.
110101 // Could be an older version, a custom build, or something a newer version with
111102 // breaking changes.
112- logger . LogWarning ( "PSReadLine unable to be loaded : {Reason}" , e ) ;
103+ logger . LogWarning ( "PSReadLineProxy unable to be initialized : {Reason}" , e ) ;
113104 return false ;
114105 }
115106 }
0 commit comments