Skip to content

Commit 75cb091

Browse files
committed
Created internal overload for CreateRunspace that accepts InitialSessionState.
Renamed initialRunspace to runspace Typecasted AdditionalModules instead of using .ToArray() to prevent cannot convert from 'System.Collections.Generic.IReadOnlyList<string>' to 'System.Collections.Generic.IEnumerable<Microsoft.PowerShell.Commands.ModuleSpecification>' compile time error. This is not ready to be merged as it needs to be rebased on master to fix test issues, and the primary objective of the changes has not been met as CommandCompletion.CompleteInput returns 0 CompletionResults when spawned from a Constrained Runspace. This may or may not require a fix from the PowerShell team as we are spawning CompleteInput from an overload of CompleteCommand that uses TabExpansion2 and there is a comment in their code indicating that this (or something related to it) is currently broken: https://github.com/PowerShell/PowerShell/blob/f4382202ae4622bf26795e29a7b39b9d7cdfb3fb/src/System.Management.Automation/engine/CommandCompletion/CommandCompletion.cs#L547
1 parent 7078073 commit 75cb091

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

src/PowerShellEditorServices/Services/PowerShellContext/PowerShellContextService.cs

+4-15
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ public static PowerShellContextService Create(
218218
hostStartupInfo.InitialSessionState.ImportPSModule((IEnumerable<Commands.ModuleSpecification>)hostStartupInfo.AdditionalModules);
219219
hostStartupInfo.InitialSessionState.ImportPSModule(new string[] { s_commandsModulePath });
220220
}
221-
Runspace initialRunspace = PowerShellContextService.CreateRunspace(psHost, hostStartupInfo.InitialSessionState);
222-
powerShellContext.Initialize(hostStartupInfo.ProfilePaths, initialRunspace, true, hostUserInterface);
221+
Runspace runspace = PowerShellContextService.CreateRunspace(psHost, hostStartupInfo.InitialSessionState);
222+
powerShellContext.Initialize(hostStartupInfo.ProfilePaths, runspace, true, hostUserInterface);
223223
// TODO: This can be moved to the point after the $psEditor object
224224
// gets initialized when that is done earlier than LanguageServer.Initialize
225225
// Darren Kattan: I haven't tested it, but I have a feeling this entire bit of logic can be replaced with the bit above for non-FullLanguage mode. I think that was is cleaner anyway.
@@ -267,26 +267,15 @@ public static Runspace CreateRunspace(
267267
powerShellContext.ConsoleReader = hostUserInterface;
268268
return CreateRunspace(psHost, hostDetails.InitialSessionState);
269269
}
270-
270+
271271
/// <summary>
272272
///
273273
/// </summary>
274274
/// <param name="psHost">The PSHost that will be used for this Runspace.</param>
275275
/// <param name="initialSessionState">The initialSessionState inherited from the orginal PowerShell process. This will be used when creating runspaces so that we honor the same initialSessionState including allowed modules, cmdlets and language mode.</param>
276276
/// <returns></returns>
277-
public static Runspace CreateRunspace(PSHost psHost, InitialSessionState initialSessionState)
277+
internal static Runspace CreateRunspace(PSHost psHost, InitialSessionState initialSessionState)
278278
{
279-
if (initialSessionState == null)
280-
{
281-
if (Environment.GetEnvironmentVariable("PSES_TEST_USE_CREATE_DEFAULT") == "1")
282-
{
283-
initialSessionState = InitialSessionState.CreateDefault();
284-
}
285-
else
286-
{
287-
initialSessionState = InitialSessionState.CreateDefault2();
288-
}
289-
}
290279
Runspace runspace = RunspaceFactory.CreateRunspace(psHost, initialSessionState);
291280

292281
// Windows PowerShell must be hosted in STA mode

0 commit comments

Comments
 (0)