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();