Skip to content

Commit ee154b0

Browse files
committed
removed #if TEST from PowerShellContextService.cs and instead provided the path as a parameter to PowerShellContextService.TryGetPSReadLineProxy()
1 parent 52b16ca commit ee154b0

File tree

4 files changed

+19
-22
lines changed

4 files changed

+19
-22
lines changed

src/PowerShellEditorServices/Services/PowerShellContext/PowerShellContextService.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ public static PowerShellContextService Create(
226226

227227
logger.LogTrace("Creating initial PowerShell runspace");
228228
Runspace initialRunspace = PowerShellContextService.CreateRunspace(psHost, hostStartupInfo.LanguageMode);
229-
powerShellContext.Initialize(hostStartupInfo.ProfilePaths, initialRunspace, true, hostUserInterface);
229+
powerShellContext.Initialize(hostStartupInfo, initialRunspace, true, hostUserInterface);
230230
powerShellContext.ImportCommandsModuleAsync();
231231

232232
// TODO: This can be moved to the point after the $psEditor object
@@ -322,7 +322,7 @@ public static Runspace CreateRunspace(PSHost psHost, PSLanguageMode languageMode
322322
/// <param name="ownsInitialRunspace">If true, the PowerShellContext owns this runspace.</param>
323323
/// <param name="consoleHost">An IHostOutput implementation. Optional.</param>
324324
public void Initialize(
325-
ProfilePathInfo profilePaths,
325+
HostStartupInfo hostStartupInfo,
326326
Runspace initialRunspace,
327327
bool ownsInitialRunspace,
328328
IHostOutput consoleHost)
@@ -376,7 +376,7 @@ public void Initialize(
376376
this.ConfigureRunspaceCapabilities(this.CurrentRunspace);
377377

378378
// Set the $profile variable in the runspace
379-
this.profilePaths = profilePaths;
379+
this.profilePaths = hostStartupInfo.ProfilePaths;
380380
if (profilePaths != null)
381381
{
382382
this.SetProfileVariableInCurrentRunspace(profilePaths);
@@ -413,7 +413,7 @@ public void Initialize(
413413

414414
if (powerShellVersion.Major >= 5 &&
415415
this.isPSReadLineEnabled &&
416-
PSReadLinePromptContext.TryGetPSReadLineProxy(logger, initialRunspace, out PSReadLineProxy proxy))
416+
PSReadLinePromptContext.TryGetPSReadLineProxy(logger, initialRunspace, hostStartupInfo.BundledModulePath, out PSReadLineProxy proxy))
417417
{
418418
this.PromptContext = new PSReadLinePromptContext(
419419
this,

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

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,6 @@ namespace Microsoft.PowerShell.EditorServices.Services.PowerShellContext
1717

1818
internal class PSReadLinePromptContext : IPromptContext
1919
{
20-
private static readonly string _psReadLineModulePath = Path.Combine(
21-
Path.GetDirectoryName(typeof(PSReadLinePromptContext).Assembly.Location),
22-
"..",
23-
"..",
24-
"..",
25-
#if TEST
26-
// When using xUnit (dotnet test) the assemblies are deployed to the
27-
// test project folder, invalidating our relative path assumption.
28-
"..",
29-
"..",
30-
"module",
31-
#endif
32-
"PSReadLine");
33-
3420
private static readonly Lazy<CmdletInfo> s_lazyInvokeReadLineForEditorServicesCmdletInfo = new Lazy<CmdletInfo>(() =>
3521
{
3622
var type = Type.GetType("Microsoft.PowerShell.EditorServices.Commands.InvokeReadLineForEditorServicesCommand, Microsoft.PowerShell.EditorServices.Hosting");
@@ -79,9 +65,11 @@ internal PSReadLinePromptContext(
7965
internal static bool TryGetPSReadLineProxy(
8066
ILogger logger,
8167
Runspace runspace,
68+
string bundledModulePath,
8269
out PSReadLineProxy readLineProxy)
8370
{
8471
readLineProxy = null;
72+
string _psReadLineModulePath = Path.Combine(bundledModulePath, "PSReadLine");
8573
logger.LogTrace("Attempting to load PSReadLine");
8674
using (var pwsh = PowerShell.Create())
8775
{

test/PowerShellEditorServices.Test/PowerShellContextFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public static PowerShellContextService Create(ILogger logger)
6363
logger);
6464

6565
powerShellContext.Initialize(
66-
TestProfilePaths,
66+
testHostDetails,
6767
initialRunspace,
6868
ownsInitialRunspace: true,
6969
consoleHost: null);

test/PowerShellEditorServices.Test/Session/PowerShellContextTests.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.IO;
77
using System.Linq;
88
using System.Management.Automation;
9+
using System.Reflection;
910
using System.Runtime.InteropServices;
1011
using System.Threading.Tasks;
1112
using Microsoft.Extensions.Logging.Abstractions;
@@ -152,10 +153,18 @@ await this.powerShellContext.ExecuteCommandAsync<string>(
152153
public async Task CanGetPSReadLineProxy()
153154
{
154155
Skip.If(IsWindows, "This test doesn't work on Windows for some reason.");
156+
string s_bundledModulesPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
157+
"..",
158+
"..",
159+
"..",
160+
"..",
161+
"module"
162+
);
155163
Assert.True(PSReadLinePromptContext.TryGetPSReadLineProxy(
156-
NullLogger.Instance,
157-
PowerShellContextFactory.initialRunspace,
158-
out PSReadLineProxy proxy));
164+
NullLogger.Instance,
165+
PowerShellContextFactory.initialRunspace,
166+
s_bundledModulesPath,
167+
out PSReadLineProxy proxy));
159168
}
160169

161170
#region Helper Methods

0 commit comments

Comments
 (0)