Skip to content

Commit 46f2324

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 d418d26 commit 46f2324

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

src/PowerShellEditorServices/Services/PowerShellContext/PowerShellContextService.cs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@ public static PowerShellContextService Create(
222222
hostStartupInfo.InitialSessionState.ImportPSModule((IEnumerable<Commands.ModuleSpecification>)hostStartupInfo.AdditionalModules);
223223
hostStartupInfo.InitialSessionState.ImportPSModule(new string[] { s_commandsModulePath });
224224
}
225-
Runspace initialRunspace = PowerShellContextService.CreateRunspace(psHost, hostStartupInfo.InitialSessionState);
226-
powerShellContext.Initialize(hostStartupInfo.ProfilePaths, initialRunspace, true, hostUserInterface);
225+
Runspace runspace = PowerShellContextService.CreateRunspace(psHost, hostStartupInfo.InitialSessionState);
226+
powerShellContext.Initialize(hostStartupInfo.ProfilePaths, runspace, true, hostUserInterface);
227227
// TODO: This can be moved to the point after the $psEditor object
228228
// gets initialized when that is done earlier than LanguageServer.Initialize
229229
// 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.
@@ -271,26 +271,15 @@ public static Runspace CreateRunspace(
271271
powerShellContext.ConsoleReader = hostUserInterface;
272272
return CreateRunspace(psHost, hostDetails.InitialSessionState);
273273
}
274-
274+
275275
/// <summary>
276276
///
277277
/// </summary>
278278
/// <param name="psHost">The PSHost that will be used for this Runspace.</param>
279279
/// <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>
280280
/// <returns></returns>
281-
public static Runspace CreateRunspace(PSHost psHost, InitialSessionState initialSessionState)
281+
internal static Runspace CreateRunspace(PSHost psHost, InitialSessionState initialSessionState)
282282
{
283-
if (initialSessionState == null)
284-
{
285-
if (Environment.GetEnvironmentVariable("PSES_TEST_USE_CREATE_DEFAULT") == "1")
286-
{
287-
initialSessionState = InitialSessionState.CreateDefault();
288-
}
289-
else
290-
{
291-
initialSessionState = InitialSessionState.CreateDefault2();
292-
}
293-
}
294283
Runspace runspace = RunspaceFactory.CreateRunspace(psHost, initialSessionState);
295284

296285
// Windows PowerShell must be hosted in STA mode

0 commit comments

Comments
 (0)