Skip to content

Commit d7ea74e

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

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/PowerShellEditorServices.Hosting/Commands/StartEditorServicesCommand.cs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,8 @@ public static PowerShellContextService Create(
219219

220220
if (hostStartupInfo.InitialSessionState.LanguageMode != PSLanguageMode.FullLanguage)
221221
{
222-
hostStartupInfo.InitialSessionState.ImportPSModule((IEnumerable<Commands.ModuleSpecification>)hostStartupInfo.AdditionalModules);
222+
if(hostStartupInfo.AdditionalModules.Count > 0)
223+
hostStartupInfo.InitialSessionState.ImportPSModule(hostStartupInfo.AdditionalModules as string[]);
223224
hostStartupInfo.InitialSessionState.ImportPSModule(new string[] { s_commandsModulePath });
224225
}
225226
Runspace runspace = PowerShellContextService.CreateRunspace(psHost, hostStartupInfo.InitialSessionState);
@@ -445,7 +446,7 @@ public void Initialize(
445446
this.PromptContext = new LegacyReadLineContext(this);
446447
}
447448

448-
if (VersionUtils.IsWindows)
449+
if (VersionUtils.IsWindows && initialRunspace.InitialSessionState.LanguageMode == PSLanguageMode.FullLanguage)
449450
{
450451
this.SetExecutionPolicy();
451452
}
@@ -2740,7 +2741,7 @@ Runspace IHostSupportsInteractiveSession.Runspace
27402741
{
27412742
get
27422743
{
2743-
return this.CurrentRunspace.Runspace;
2744+
return this.CurrentRunspace?.Runspace;
27442745
}
27452746
}
27462747

0 commit comments

Comments
 (0)