Skip to content

Commit 798f429

Browse files
committed
This works in a constrained runspace, but performance poor as PSES continuously attempts to resolve missing cmdlets.
1 parent 81fb639 commit 798f429

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/PowerShellEditorServices.Hosting/Commands/StartEditorServicesCommand.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ private EditorServicesConfig CreateConfigObject()
351351
var profile = (PSObject)GetVariableValue("profile");
352352

353353
var hostInfo = new HostInfo(HostName, HostProfileId, HostVersion);
354-
var initialSessionState = InitialSessionState ?? Runspace.DefaultRunspace.InitialSessionState;
354+
var initialSessionState = Runspace.DefaultRunspace.InitialSessionState;
355355
var editorServicesConfig = new EditorServicesConfig(hostInfo, Host, SessionDetailsPath, bundledModulesPath, LogPath)
356356
{
357357
FeatureFlags = FeatureFlags,

src/PowerShellEditorServices/Services/PowerShellContext/PowerShellContextService.cs

+4-3
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,8 @@ public static PowerShellContextService Create(
215215

216216
if (hostStartupInfo.InitialSessionState.LanguageMode != PSLanguageMode.FullLanguage)
217217
{
218-
hostStartupInfo.InitialSessionState.ImportPSModule((IEnumerable<Commands.ModuleSpecification>)hostStartupInfo.AdditionalModules);
218+
if(hostStartupInfo.AdditionalModules.Count > 0)
219+
hostStartupInfo.InitialSessionState.ImportPSModule(hostStartupInfo.AdditionalModules as string[]);
219220
hostStartupInfo.InitialSessionState.ImportPSModule(new string[] { s_commandsModulePath });
220221
}
221222
Runspace runspace = PowerShellContextService.CreateRunspace(psHost, hostStartupInfo.InitialSessionState);
@@ -441,7 +442,7 @@ public void Initialize(
441442
this.PromptContext = new LegacyReadLineContext(this);
442443
}
443444

444-
if (VersionUtils.IsWindows)
445+
if (VersionUtils.IsWindows && initialRunspace.InitialSessionState.LanguageMode == PSLanguageMode.FullLanguage)
445446
{
446447
this.SetExecutionPolicy();
447448
}
@@ -2714,7 +2715,7 @@ Runspace IHostSupportsInteractiveSession.Runspace
27142715
{
27152716
get
27162717
{
2717-
return this.CurrentRunspace.Runspace;
2718+
return this.CurrentRunspace?.Runspace;
27182719
}
27192720
}
27202721

0 commit comments

Comments
 (0)