From 37b312e375337112bcf3165e88f56d1fa8148c23 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Wed, 14 Jun 2017 21:41:44 -0700 Subject: [PATCH] Enable debug-only PowerShell Editor Services sessions This change finishes the work necessary to enable debug-only sessions where a new PowerShell process is launched strictly for the purpose of providing a fresh debugging session. This is useful when debugging modules which use PowerShell classes or binary components which cannot be reloaded in the same process. Part of the implementation for PowerShell/vscode-powershell#367. --- .../PowerShellEditorServices.psm1 | 2 +- .../EditorServicesHost.cs | 52 +++++++++---------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/module/PowerShellEditorServices/PowerShellEditorServices.psm1 b/module/PowerShellEditorServices/PowerShellEditorServices.psm1 index b13b2ad18..de47ff7b3 100644 --- a/module/PowerShellEditorServices/PowerShellEditorServices.psm1 +++ b/module/PowerShellEditorServices/PowerShellEditorServices.psm1 @@ -49,7 +49,7 @@ function Start-EditorServicesHost { [switch] $EnableConsoleRepl, - [string] + [switch] $DebugServiceOnly, [string[]] diff --git a/src/PowerShellEditorServices.Host/EditorServicesHost.cs b/src/PowerShellEditorServices.Host/EditorServicesHost.cs index 5d9013f39..c3807f4c2 100644 --- a/src/PowerShellEditorServices.Host/EditorServicesHost.cs +++ b/src/PowerShellEditorServices.Host/EditorServicesHost.cs @@ -256,44 +256,44 @@ private void OnDebugServiceClientConnect(object sender, TcpSocketServerChannel s protocolEndpoint.UnhandledException += ProtocolEndpoint_UnhandledException; - if (this.enableConsoleRepl) - { - this.debugAdapter = - new DebugAdapter( - this.editorSession, - false, - messageDispatcher, - protocolEndpoint, - this.logger); - } - else + bool ownsEditorSession = this.editorSession == null; + + if (ownsEditorSession) { - EditorSession debugSession = + this.editorSession = this.CreateDebugSession( this.hostDetails, profilePaths, protocolEndpoint, messageDispatcher, this.languageServer?.EditorOperations, - false); - - this.debugAdapter = - new DebugAdapter( - debugSession, - true, - messageDispatcher, - protocolEndpoint, - this.logger); + this.enableConsoleRepl); } + this.debugAdapter = + new DebugAdapter( + this.editorSession, + ownsEditorSession, + messageDispatcher, + protocolEndpoint, + this.logger); + this.debugAdapter.SessionEnded += (obj, args) => { - this.logger.Write( - LogLevel.Normal, - "Previous debug session ended, restarting debug service listener..."); - - this.debugServiceListener.Start(); + if (!ownsEditorSession) + { + this.logger.Write( + LogLevel.Normal, + "Previous debug session ended, restarting debug service listener..."); + + this.debugServiceListener.Start(); + } + else + { + // Exit the host process + this.serverCompletedTask.SetResult(true); + } }; this.debugAdapter.Start();