Skip to content

Commit f353d72

Browse files
committed
Added support for runspaces without FileSystem Providers
1 parent 00c7824 commit f353d72

26 files changed

+305
-164
lines changed

PowerShellEditorServices.build.ps1

+2-2
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ task Clean BinClean,{
134134
exec { & $script:dotnetExe clean }
135135
Get-ChildItem -Recurse $PSScriptRoot\src\*.nupkg | Remove-Item -Force -ErrorAction Ignore
136136
Get-ChildItem $PSScriptRoot\PowerShellEditorServices*.zip | Remove-Item -Force -ErrorAction Ignore
137-
Get-ChildItem $PSScriptRoot\module\PowerShellEditorServices\Commands\en-US\*-help.xml | Remove-Item -Force -ErrorAction Ignore
137+
Get-ChildItem $PSScriptRoot\module\PowerShellEditorServices.Commands\en-US\*-help.xml | Remove-Item -Force -ErrorAction Ignore
138138

139139
# Remove bundled component modules
140140
$moduleJsonPath = "$PSScriptRoot\modules.json"
@@ -406,7 +406,7 @@ task RestorePsesModules -After Build {
406406
}
407407

408408
task BuildCmdletHelp {
409-
New-ExternalHelp -Path $PSScriptRoot\module\docs -OutputPath $PSScriptRoot\module\PowerShellEditorServices\Commands\en-US -Force
409+
New-ExternalHelp -Path $PSScriptRoot\module\docs -OutputPath $PSScriptRoot\module\PowerShellEditorServices.Commands\en-US -Force
410410
New-ExternalHelp -Path $PSScriptRoot\module\PowerShellEditorServices.VSCode\docs -OutputPath $PSScriptRoot\module\PowerShellEditorServices.VSCode\en-US -Force
411411
}
412412

module/PowerShellEditorServices/Commands/PowerShellEditorServices.Commands.types.ps1xml renamed to module/PowerShellEditorServices.Commands/PowerShellEditorServices.Commands.types.ps1xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@
2525
</MemberSet>
2626
</Members>
2727
</Type>
28-
</Types>
28+
</Types>

module/PowerShellEditorServices/InvokePesterStub.ps1

100755100644
File mode changed.

src/PowerShellEditorServices.Hosting/Commands/InvokeReadLineForEditorServicesCommand.cs

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT License.
33

44
using System;
5+
using System.Linq;
56
using System.Management.Automation;
67
using System.Management.Automation.Runspaces;
78
using System.Reflection;
@@ -21,12 +22,12 @@ private delegate string ReadLineInvoker(
2122

2223
private static Lazy<ReadLineInvoker> s_readLine = new Lazy<ReadLineInvoker>(() =>
2324
{
24-
Type type = Type.GetType("Microsoft.PowerShell.PSConsoleReadLine, Microsoft.PowerShell.PSReadLine2");
25+
var allAssemblies = AppDomain.CurrentDomain.GetAssemblies();
26+
var assemblies = allAssemblies.FirstOrDefault(a => a.FullName.Contains("Microsoft.PowerShell.PSReadLine2"));
27+
var type = assemblies?.ExportedTypes?.FirstOrDefault(a => a.FullName == "Microsoft.PowerShell.PSConsoleReadLine");
2528
MethodInfo method = type?.GetMethod(
2629
"ReadLine",
27-
new[] { typeof(Runspace), typeof(EngineIntrinsics), typeof(CancellationToken) });
28-
29-
// TODO: Handle method being null here. This shouldn't ever happen.
30+
new [] { typeof(Runspace), typeof(EngineIntrinsics), typeof(CancellationToken) });
3031

3132
return (ReadLineInvoker)method.CreateDelegate(typeof(ReadLineInvoker));
3233
});

src/PowerShellEditorServices.Hosting/Internal/EditorServicesRunner.cs

+9-9
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ private async Task CreateEditorServicesAndRunUntilShutdown()
137137
HostStartupInfo hostStartupInfo = CreateHostStartupInfo();
138138

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

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

168168
Task<PsesDebugServer> debugServerCreation = null;
169-
if (creatingDebugServer)
169+
if(creatingDebugServer)
170170
{
171171
debugServerCreation = CreateDebugServerWithLanguageServerAsync(languageServer, usePSReadLine: _config.ConsoleRepl == ConsoleReplKind.PSReadLine);
172172
}
173173

174174
Task languageServerStart = languageServer.StartAsync();
175175

176176
Task debugServerStart = null;
177-
if (creatingDebugServer)
177+
if(creatingDebugServer)
178178
{
179179
// We don't need to wait for this to start, since we instead wait for it to complete later
180180
debugServerStart = StartDebugServer(debugServerCreation);
181181
}
182182

183183
await languageServerStart.ConfigureAwait(false);
184-
if (debugServerStart != null)
184+
if(debugServerStart != null)
185185
{
186186
await debugServerStart.ConfigureAwait(false);
187187
}
@@ -210,7 +210,7 @@ private async Task StartDebugServer(Task<PsesDebugServer> debugServerCreation)
210210

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

270270
ProfilePathInfo profilePaths = null;
271-
if (_config.ProfilePaths.AllUsersAllHosts != null
271+
if(_config.ProfilePaths.AllUsersAllHosts != null
272272
|| _config.ProfilePaths.AllUsersCurrentHost != null
273273
|| _config.ProfilePaths.CurrentUserAllHosts != null
274274
|| _config.ProfilePaths.CurrentUserCurrentHost != null)
@@ -298,7 +298,7 @@ private HostStartupInfo CreateHostStartupInfo()
298298

299299
private void WriteStartupBanner()
300300
{
301-
if (_config.ConsoleRepl == ConsoleReplKind.None)
301+
if(_config.ConsoleRepl == ConsoleReplKind.None)
302302
{
303303
return;
304304
}

src/PowerShellEditorServices/Hosting/HostStartupInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ public sealed class HostStartupInfo
9292
public string LogPath { get; }
9393

9494
/// <summary>
95-
/// The InitialSessionState will be inherited from the orginal PowerShell process. This will
96-
/// be used when creating runspaces so that we honor the same InitialSessionState.
95+
/// The initialSessionState will be inherited from the orginal PowerShell process.
96+
/// This will be used when creating runspaces so that we honor the same initialSessionState including allowed modules, cmdlets and language mode.
9797
/// </summary>
9898
public InitialSessionState InitialSessionState { get; }
9999

0 commit comments

Comments
 (0)