Skip to content

Commit 13c63ac

Browse files
committed
Replace inline script with AddCommand
1 parent 69cf407 commit 13c63ac

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

src/PowerShellEditorServices/Services/PowerShellContext/Session/PSReadLinePromptContext.cs

+3-11
Original file line numberDiff line numberDiff line change
@@ -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");
@@ -90,7 +80,9 @@ internal static bool TryGetPSReadLineProxy(
9080
{
9181
pwsh.Runspace = runspace;
9282
var psReadLineType = pwsh
93-
.AddScript(ReadLineInitScript, useLocalScope: true)
83+
.AddCommand("Microsoft.PowerShell.Core\\Import-Module")
84+
.AddParameter("Name", _psReadLineModulePath)
85+
.AddCommand("return [Microsoft.PowerShell.PSConsoleReadLine]")
9486
.Invoke<Type>()
9587
.FirstOrDefault();
9688

0 commit comments

Comments
 (0)