Skip to content

Constrained Runspace Support #1507

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions PowerShellEditorServices.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ task Clean BinClean,{
exec { & $script:dotnetExe clean }
Get-ChildItem -Recurse $PSScriptRoot\src\*.nupkg | Remove-Item -Force -ErrorAction Ignore
Get-ChildItem $PSScriptRoot\PowerShellEditorServices*.zip | Remove-Item -Force -ErrorAction Ignore
Get-ChildItem $PSScriptRoot\module\PowerShellEditorServices\Commands\en-US\*-help.xml | Remove-Item -Force -ErrorAction Ignore
Get-ChildItem $PSScriptRoot\module\PowerShellEditorServices.Commands\en-US\*-help.xml | Remove-Item -Force -ErrorAction Ignore

# Remove bundled component modules
$moduleJsonPath = "$PSScriptRoot\modules.json"
Expand Down Expand Up @@ -406,7 +406,7 @@ task RestorePsesModules -After Build {
}

task BuildCmdletHelp {
New-ExternalHelp -Path $PSScriptRoot\module\docs -OutputPath $PSScriptRoot\module\PowerShellEditorServices\Commands\en-US -Force
New-ExternalHelp -Path $PSScriptRoot\module\docs -OutputPath $PSScriptRoot\module\PowerShellEditorServices.Commands\en-US -Force
New-ExternalHelp -Path $PSScriptRoot\module\PowerShellEditorServices.VSCode\docs -OutputPath $PSScriptRoot\module\PowerShellEditorServices.VSCode\en-US -Force
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@
</MemberSet>
</Members>
</Type>
</Types>
</Types>
Empty file modified module/PowerShellEditorServices/InvokePesterStub.ps1
100755 → 100644
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.

using System;
using System.Linq;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using System.Reflection;
Expand All @@ -21,12 +22,12 @@ private delegate string ReadLineInvoker(

private static Lazy<ReadLineInvoker> s_readLine = new Lazy<ReadLineInvoker>(() =>
{
Type type = Type.GetType("Microsoft.PowerShell.PSConsoleReadLine, Microsoft.PowerShell.PSReadLine2");
var allAssemblies = AppDomain.CurrentDomain.GetAssemblies();
var assemblies = allAssemblies.FirstOrDefault(a => a.FullName.Contains("Microsoft.PowerShell.PSReadLine2"));
var type = assemblies?.ExportedTypes?.FirstOrDefault(a => a.FullName == "Microsoft.PowerShell.PSConsoleReadLine");
MethodInfo method = type?.GetMethod(
"ReadLine",
new[] { typeof(Runspace), typeof(EngineIntrinsics), typeof(CancellationToken) });

// TODO: Handle method being null here. This shouldn't ever happen.
new [] { typeof(Runspace), typeof(EngineIntrinsics), typeof(CancellationToken) });

return (ReadLineInvoker)method.CreateDelegate(typeof(ReadLineInvoker));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ private async Task CreateEditorServicesAndRunUntilShutdown()
HostStartupInfo hostStartupInfo = CreateHostStartupInfo();

// If we just want a temp debug session, run that and do nothing else
if (isTempDebugSession)
if(isTempDebugSession)
{
await RunTempDebugSessionAsync(hostStartupInfo).ConfigureAwait(false);
return;
Expand All @@ -153,9 +153,9 @@ private async Task CreateEditorServicesAndRunUntilShutdown()

// Unsubscribe the host logger here so that the integrated console is not polluted with input after the first prompt
_logger.Log(PsesLogLevel.Verbose, "Starting server, deregistering host logger and registering shutdown listener");
if (_loggersToUnsubscribe != null)
if(_loggersToUnsubscribe != null)
{
foreach (IDisposable loggerToUnsubscribe in _loggersToUnsubscribe)
foreach(IDisposable loggerToUnsubscribe in _loggersToUnsubscribe)
{
loggerToUnsubscribe.Dispose();
}
Expand All @@ -166,22 +166,22 @@ private async Task CreateEditorServicesAndRunUntilShutdown()
PsesLanguageServer languageServer = await CreateLanguageServerAsync(hostStartupInfo).ConfigureAwait(false);

Task<PsesDebugServer> debugServerCreation = null;
if (creatingDebugServer)
if(creatingDebugServer)
{
debugServerCreation = CreateDebugServerWithLanguageServerAsync(languageServer, usePSReadLine: _config.ConsoleRepl == ConsoleReplKind.PSReadLine);
}

Task languageServerStart = languageServer.StartAsync();

Task debugServerStart = null;
if (creatingDebugServer)
if(creatingDebugServer)
{
// We don't need to wait for this to start, since we instead wait for it to complete later
debugServerStart = StartDebugServer(debugServerCreation);
}

await languageServerStart.ConfigureAwait(false);
if (debugServerStart != null)
if(debugServerStart != null)
{
await debugServerStart.ConfigureAwait(false);
}
Expand Down Expand Up @@ -210,7 +210,7 @@ private async Task StartDebugServer(Task<PsesDebugServer> debugServerCreation)

// When the debug server shuts down, we want it to automatically restart
// To do this, we set an event to allow it to create a new debug server as its session ends
if (!_alreadySubscribedDebug)
if(!_alreadySubscribedDebug)
{
_logger.Log(PsesLogLevel.Diagnostic, "Subscribing debug server for session ended event");
_alreadySubscribedDebug = true;
Expand Down Expand Up @@ -268,7 +268,7 @@ private HostStartupInfo CreateHostStartupInfo()
_logger.Log(PsesLogLevel.Diagnostic, "Creating startup info object");

ProfilePathInfo profilePaths = null;
if (_config.ProfilePaths.AllUsersAllHosts != null
if(_config.ProfilePaths.AllUsersAllHosts != null
|| _config.ProfilePaths.AllUsersCurrentHost != null
|| _config.ProfilePaths.CurrentUserAllHosts != null
|| _config.ProfilePaths.CurrentUserCurrentHost != null)
Expand Down Expand Up @@ -298,7 +298,7 @@ private HostStartupInfo CreateHostStartupInfo()

private void WriteStartupBanner()
{
if (_config.ConsoleRepl == ConsoleReplKind.None)
if(_config.ConsoleRepl == ConsoleReplKind.None)
{
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/PowerShellEditorServices/Hosting/HostStartupInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ public sealed class HostStartupInfo
public string LogPath { get; }

/// <summary>
/// The InitialSessionState will be inherited from the orginal PowerShell process. This will
/// be used when creating runspaces so that we honor the same InitialSessionState.
/// The initialSessionState will be 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.
/// </summary>
public InitialSessionState InitialSessionState { get; }

Expand Down
Loading