Skip to content

Commit 9e32514

Browse files
committed
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.
1 parent 7fa57e3 commit 9e32514

File tree

2 files changed

+27
-27
lines changed

2 files changed

+27
-27
lines changed

module/PowerShellEditorServices/PowerShellEditorServices.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function Start-EditorServicesHost {
4949
[switch]
5050
$EnableConsoleRepl,
5151

52-
[string]
52+
[switch]
5353
$DebugServiceOnly,
5454

5555
[string[]]

src/PowerShellEditorServices.Host/EditorServicesHost.cs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -256,44 +256,44 @@ private void OnDebugServiceClientConnect(object sender, TcpSocketServerChannel s
256256

257257
protocolEndpoint.UnhandledException += ProtocolEndpoint_UnhandledException;
258258

259-
if (this.enableConsoleRepl)
260-
{
261-
this.debugAdapter =
262-
new DebugAdapter(
263-
this.editorSession,
264-
false,
265-
messageDispatcher,
266-
protocolEndpoint,
267-
this.logger);
268-
}
269-
else
259+
bool ownsEditorSession = this.editorSession == null;
260+
261+
if (ownsEditorSession)
270262
{
271-
EditorSession debugSession =
263+
this.editorSession =
272264
this.CreateDebugSession(
273265
this.hostDetails,
274266
profilePaths,
275267
protocolEndpoint,
276268
messageDispatcher,
277269
this.languageServer?.EditorOperations,
278-
false);
279-
280-
this.debugAdapter =
281-
new DebugAdapter(
282-
debugSession,
283-
true,
284-
messageDispatcher,
285-
protocolEndpoint,
286-
this.logger);
270+
this.enableConsoleRepl);
287271
}
288272

273+
this.debugAdapter =
274+
new DebugAdapter(
275+
this.editorSession,
276+
ownsEditorSession,
277+
messageDispatcher,
278+
protocolEndpoint,
279+
this.logger);
280+
289281
this.debugAdapter.SessionEnded +=
290282
(obj, args) =>
291283
{
292-
this.logger.Write(
293-
LogLevel.Normal,
294-
"Previous debug session ended, restarting debug service listener...");
295-
296-
this.debugServiceListener.Start();
284+
if (!ownsEditorSession)
285+
{
286+
this.logger.Write(
287+
LogLevel.Normal,
288+
"Previous debug session ended, restarting debug service listener...");
289+
290+
this.debugServiceListener.Start();
291+
}
292+
else
293+
{
294+
// Exit the host process
295+
this.serverCompletedTask.SetResult(true);
296+
}
297297
};
298298

299299
this.debugAdapter.Start();

0 commit comments

Comments
 (0)