Skip to content

Commit 0fcf4d2

Browse files
address rob's feedback
1 parent 35bfefe commit 0fcf4d2

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed

src/PowerShellEditorServices/Hosting/EditorServicesHost.cs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -284,16 +284,16 @@ public void StartLanguageService(
284284
/// </summary>
285285
/// <param name="config">The config that contains information on the communication protocol that will be used.</param>
286286
/// <param name="profilePaths">The profiles that will be loaded in the session.</param>
287-
/// <param name="useExistingSession">Determines if we will reuse the session that we have.</param>
287+
/// <param name="useTempSession">Determines if we will make a new session typically used for temporary console debugging.</param>
288288
public void StartDebugService(
289289
EditorServiceTransportConfig config,
290290
ProfilePaths profilePaths,
291-
bool useExistingSession)
291+
bool useTempSession)
292292
{
293293
_logger.LogInformation($"Debug NamedPipe: {config.InOutPipeName}\nDebug OutPipe: {config.OutPipeName}");
294294

295295
IServiceProvider serviceProvider = null;
296-
if (!useExistingSession)
296+
if (useTempSession)
297297
{
298298
serviceProvider = new ServiceCollection()
299299
.AddLogging(builder => builder
@@ -331,7 +331,7 @@ public void StartDebugService(
331331
.ContinueWith(async task =>
332332
{
333333
_logger.LogInformation("Starting debug server");
334-
await _debugServer.StartAsync(serviceProvider ?? _languageServer.LanguageServer.Services, useExistingSession);
334+
await _debugServer.StartAsync(serviceProvider ?? _languageServer.LanguageServer.Services, useTempSession);
335335
_logger.LogInformation(
336336
$"Debug service started, type = {config.TransportType}, endpoint = {config.Endpoint}");
337337
});
@@ -348,7 +348,7 @@ public void StartDebugService(
348348
Task.Run(async () =>
349349
{
350350

351-
await _debugServer.StartAsync(serviceProvider ?? _languageServer.LanguageServer.Services, useExistingSession);
351+
await _debugServer.StartAsync(serviceProvider ?? _languageServer.LanguageServer.Services, useTempSession);
352352
_logger.LogInformation(
353353
$"Debug service started, type = {config.TransportType}, endpoint = {config.Endpoint}");
354354
});
@@ -363,14 +363,14 @@ public void StartDebugService(
363363
// This design decision was done since this "debug-only PSES" is used in the "Temporary Integrated Console debugging"
364364
// feature which does not want PSES to be restarted so that the user can see the output of the last debug
365365
// session.
366-
if(!alreadySubscribedDebug && useExistingSession)
366+
if(!alreadySubscribedDebug && !useTempSession)
367367
{
368368
alreadySubscribedDebug = true;
369369
_debugServer.SessionEnded += (sender, eventArgs) =>
370370
{
371371
_debugServer.Dispose();
372372
alreadySubscribedDebug = false;
373-
StartDebugService(config, profilePaths, useExistingSession);
373+
StartDebugService(config, profilePaths, useTempSession);
374374
};
375375
}
376376
}
@@ -388,12 +388,19 @@ public void StopServices()
388388
/// </summary>
389389
public void WaitForCompletion()
390390
{
391-
// TODO: We need a way to know when to complete this task!
391+
// If _languageServer is not null, then we are either using:
392+
// Stdio - that only uses a LanguageServer so we return when that has shutdown.
393+
// NamedPipes - that uses both LanguageServer and DebugServer, but LanguageServer
394+
// is the core of PowerShell Editor Services and if that shuts down,
395+
// we want the whole process to shutdown.
392396
if (_languageServer != null)
393397
{
394398
_languageServer.WaitForShutdown().Wait();
395399
return;
396400
}
401+
402+
// If there is no LanguageServer, then we must be running with the DebugServiceOnly switch
403+
// (used in Temporary console debugging) and we need to wait for the DebugServer to shutdown.
397404
_debugServer.WaitForShutdown().Wait();
398405
}
399406

src/PowerShellEditorServices/Server/PsesDebugServer.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class PsesDebugServer : IDisposable
2626

2727
private PowerShellContextService _powerShellContextService;
2828

29-
private readonly TaskCompletionSource<bool> _serverStart;
29+
private readonly TaskCompletionSource<bool> _serverRunning;
3030

3131
public PsesDebugServer(
3232
ILoggerFactory factory,
@@ -36,10 +36,10 @@ public PsesDebugServer(
3636
_loggerFactory = factory;
3737
_inputStream = inputStream;
3838
_outputStream = outputStream;
39-
_serverStart = new TaskCompletionSource<bool>();
39+
_serverRunning = new TaskCompletionSource<bool>();
4040
}
4141

42-
public async Task StartAsync(IServiceProvider languageServerServiceProvider, bool useExistingSession)
42+
public async Task StartAsync(IServiceProvider languageServerServiceProvider, bool useTempSession)
4343
{
4444
_jsonRpcServer = await JsonRpcServer.From(options =>
4545
{
@@ -59,7 +59,7 @@ public async Task StartAsync(IServiceProvider languageServerServiceProvider, boo
5959
.Wait();
6060

6161
options.Services = new ServiceCollection()
62-
.AddPsesDebugServices(languageServerServiceProvider, this, useExistingSession);
62+
.AddPsesDebugServices(languageServerServiceProvider, this, useTempSession);
6363

6464
options
6565
.WithInput(_inputStream)
@@ -97,12 +97,12 @@ public void Dispose()
9797
{
9898
_powerShellContextService.IsDebugServerActive = false;
9999
_jsonRpcServer.Dispose();
100-
_serverStart.SetResult(true);
100+
_serverRunning.SetResult(true);
101101
}
102102

103103
public async Task WaitForShutdown()
104104
{
105-
await _serverStart.Task;
105+
await _serverRunning.Task;
106106
}
107107

108108
#region Events

src/PowerShellEditorServices/Server/PsesServiceCollection.cs renamed to src/PowerShellEditorServices/Server/PsesServiceCollectionExtensions.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//
1+
//
22
// Copyright (c) Microsoft. All rights reserved.
33
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
44
//
@@ -13,7 +13,7 @@
1313

1414
namespace Microsoft.PowerShell.EditorServices.Server
1515
{
16-
internal static class PsesServiceCollection
16+
internal static class PsesServiceCollectionExtensions
1717
{
1818
public static IServiceCollection AddPsesLanguageServices (
1919
this IServiceCollection collection,
@@ -67,7 +67,7 @@ public static IServiceCollection AddPsesDebugServices (
6767
this IServiceCollection collection,
6868
IServiceProvider languageServiceProvider,
6969
PsesDebugServer psesDebugServer,
70-
bool useExistingSession
70+
bool useTempSession
7171
)
7272
{
7373
return collection.AddSingleton(languageServiceProvider.GetService<PowerShellContextService>())
@@ -77,7 +77,7 @@ bool useExistingSession
7777
.AddSingleton<DebugService>()
7878
.AddSingleton<DebugStateService>(new DebugStateService
7979
{
80-
OwnsEditorSession = !useExistingSession
80+
OwnsEditorSession = useTempSession
8181
})
8282
.AddSingleton<DebugEventHandlerService>();
8383
}

0 commit comments

Comments
 (0)