@@ -284,16 +284,16 @@ public void StartLanguageService(
284
284
/// </summary>
285
285
/// <param name="config">The config that contains information on the communication protocol that will be used.</param>
286
286
/// <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>
288
288
public void StartDebugService (
289
289
EditorServiceTransportConfig config ,
290
290
ProfilePaths profilePaths ,
291
- bool useExistingSession )
291
+ bool useTempSession )
292
292
{
293
293
_logger . LogInformation ( $ "Debug NamedPipe: { config . InOutPipeName } \n Debug OutPipe: { config . OutPipeName } ") ;
294
294
295
295
IServiceProvider serviceProvider = null ;
296
- if ( ! useExistingSession )
296
+ if ( useTempSession )
297
297
{
298
298
serviceProvider = new ServiceCollection ( )
299
299
. AddLogging ( builder => builder
@@ -331,7 +331,7 @@ public void StartDebugService(
331
331
. ContinueWith ( async task =>
332
332
{
333
333
_logger . LogInformation ( "Starting debug server" ) ;
334
- await _debugServer . StartAsync ( serviceProvider ?? _languageServer . LanguageServer . Services , useExistingSession ) ;
334
+ await _debugServer . StartAsync ( serviceProvider ?? _languageServer . LanguageServer . Services , useTempSession ) ;
335
335
_logger . LogInformation (
336
336
$ "Debug service started, type = { config . TransportType } , endpoint = { config . Endpoint } ") ;
337
337
} ) ;
@@ -348,7 +348,7 @@ public void StartDebugService(
348
348
Task . Run ( async ( ) =>
349
349
{
350
350
351
- await _debugServer . StartAsync ( serviceProvider ?? _languageServer . LanguageServer . Services , useExistingSession ) ;
351
+ await _debugServer . StartAsync ( serviceProvider ?? _languageServer . LanguageServer . Services , useTempSession ) ;
352
352
_logger . LogInformation (
353
353
$ "Debug service started, type = { config . TransportType } , endpoint = { config . Endpoint } ") ;
354
354
} ) ;
@@ -363,14 +363,14 @@ public void StartDebugService(
363
363
// This design decision was done since this "debug-only PSES" is used in the "Temporary Integrated Console debugging"
364
364
// feature which does not want PSES to be restarted so that the user can see the output of the last debug
365
365
// session.
366
- if ( ! alreadySubscribedDebug && useExistingSession )
366
+ if ( ! alreadySubscribedDebug && ! useTempSession )
367
367
{
368
368
alreadySubscribedDebug = true ;
369
369
_debugServer . SessionEnded += ( sender , eventArgs ) =>
370
370
{
371
371
_debugServer . Dispose ( ) ;
372
372
alreadySubscribedDebug = false ;
373
- StartDebugService ( config , profilePaths , useExistingSession ) ;
373
+ StartDebugService ( config , profilePaths , useTempSession ) ;
374
374
} ;
375
375
}
376
376
}
@@ -388,12 +388,19 @@ public void StopServices()
388
388
/// </summary>
389
389
public void WaitForCompletion ( )
390
390
{
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.
392
396
if ( _languageServer != null )
393
397
{
394
398
_languageServer . WaitForShutdown ( ) . Wait ( ) ;
395
399
return ;
396
400
}
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.
397
404
_debugServer . WaitForShutdown ( ) . Wait ( ) ;
398
405
}
399
406
0 commit comments