From aca8ca3c849a28b44c8f314340ed9a353ec561fa Mon Sep 17 00:00:00 2001 From: Jordan Borean Date: Mon, 4 Aug 2025 10:18:12 +1000 Subject: [PATCH 1/2] Add temporaryConsoleWindowActionOnDebugEnd option Adds a new option `temporaryConsoleWindowActionOnDebugEnd` to both the attach and launch configurations which can be used to specify what happens with the temporary integrated console when a debug session ends. The option can be set to `keep`, current behaviour and default, that will keep the active terminal as the temporary console. It can be set to `close` which closes the terminal and removes it from the selection pane or `hide` which keeps the terminal window alive but changes the active terminal to the previous one before the debug session started. --- package.json | 30 ++++++++++++++++++++++++++++++ src/features/DebugSession.ts | 23 +++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/package.json b/package.json index f86e867977..2a1f0877f9 100644 --- a/package.json +++ b/package.json @@ -581,6 +581,21 @@ "type": "string", "description": "If you would like to use a custom coreclr attach debug launch configuration for the debug session, specify the name here. Otherwise a default basic config will be used. The config must be a coreclr attach config. Launch configs are not supported.", "default": false + }, + "temporaryConsoleWindowActionOnDebugEnd": { + "type": "string", + "description": "Determines whether the temporary PowerShell Extension Terminal is closed when the debugging session ends.", + "default": "keep", + "enum": [ + "close", + "hide", + "keep" + ], + "enumDescriptions": [ + "Closes the temporary PowerShell Extension Terminal when the debugging session ends.", + "Hides the temporary PowerShell Extension Terminal when the debugging session ends and restores the previous window before the debug session had started. This does nothing if the previous window was closed during the debug session.", + "Keeps the temporary PowerShell Extension Terminal open after the debugging session ends." + ] } } }, @@ -615,6 +630,21 @@ "type": "boolean", "description": "Determines whether a temporary PowerShell Extension Terminal is created for each debugging session, useful for debugging PowerShell classes and binary modules. Overrides the user setting 'powershell.debugging.createTemporaryIntegratedConsole'.", "default": false + }, + "temporaryConsoleWindowActionOnDebugEnd": { + "type": "string", + "description": "Determines whether the temporary PowerShell Extension Terminal is closed when the debugging session ends.", + "default": "keep", + "enum": [ + "close", + "hide", + "keep" + ], + "enumDescriptions": [ + "Closes the temporary PowerShell Extension Terminal when the debugging session ends.", + "Hides the temporary PowerShell Extension Terminal when the debugging session ends and restores the previous window before the debug session had started. This does nothing if the previous window was closed during the debug session.", + "Keeps the temporary PowerShell Extension Terminal open after the debugging session ends." + ] } } } diff --git a/src/features/DebugSession.ts b/src/features/DebugSession.ts index 3128db3b46..eef8cdc7ec 100644 --- a/src/features/DebugSession.ts +++ b/src/features/DebugSession.ts @@ -466,6 +466,8 @@ export class DebugSessionFeature return this.resolveAttachDotnetDebugConfiguration(config); } + config.temporaryConsoleWindowActionOnDebugEnd ??= "keep"; + return config; } @@ -498,6 +500,8 @@ export class DebugSessionFeature session: DebugSession, ): Promise { const settings = getSettings(); + const previousActiveTerminal = window.activeTerminal; + this.tempDebugProcess = await this.sessionManager.createDebugSessionProcess( settings, @@ -600,6 +604,23 @@ export class DebugSessionFeature ); } + const closeDebugEvent = debug.onDidTerminateDebugSession( + (terminatedSession) => { + closeDebugEvent.dispose(); + + if (terminatedSession.id !== session.id) { + return; + } + + if (terminatedSession.configuration.temporaryConsoleWindowActionOnDebugEnd === "close") { + this.tempDebugProcess?.dispose(); + } else if (terminatedSession.configuration.temporaryConsoleWindowActionOnDebugEnd === "hide" && + window.terminals.includes(previousActiveTerminal)) { + previousActiveTerminal.show(); + } + }, + ); + return this.tempSessionDetails; } @@ -705,6 +726,8 @@ export class DebugSessionFeature } } + config.temporaryConsoleWindowActionOnDebugEnd ??= "keep"; + return config; } From a17ce7a49cc7674a9dee0a62b73bd7b6bcf9d47f Mon Sep 17 00:00:00 2001 From: Jordan Borean Date: Mon, 4 Aug 2025 10:41:19 +1000 Subject: [PATCH 2/2] Prettier formatting fixes --- src/features/DebugSession.ts | 41 ++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/src/features/DebugSession.ts b/src/features/DebugSession.ts index eef8cdc7ec..49e964c44e 100644 --- a/src/features/DebugSession.ts +++ b/src/features/DebugSession.ts @@ -604,22 +604,35 @@ export class DebugSessionFeature ); } - const closeDebugEvent = debug.onDidTerminateDebugSession( - (terminatedSession) => { - closeDebugEvent.dispose(); + if ( + session.configuration.temporaryConsoleWindowActionOnDebugEnd !== + "keep" + ) { + const closeDebugEvent = debug.onDidTerminateDebugSession( + (terminatedSession) => { + closeDebugEvent.dispose(); - if (terminatedSession.id !== session.id) { - return; - } + if (terminatedSession.id !== session.id) { + return; + } - if (terminatedSession.configuration.temporaryConsoleWindowActionOnDebugEnd === "close") { - this.tempDebugProcess?.dispose(); - } else if (terminatedSession.configuration.temporaryConsoleWindowActionOnDebugEnd === "hide" && - window.terminals.includes(previousActiveTerminal)) { - previousActiveTerminal.show(); - } - }, - ); + if ( + terminatedSession.configuration + .temporaryConsoleWindowActionOnDebugEnd === "close" + ) { + this.tempDebugProcess?.dispose(); + } else if ( + terminatedSession.configuration + .temporaryConsoleWindowActionOnDebugEnd === + "hide" && + previousActiveTerminal && + window.terminals.includes(previousActiveTerminal) + ) { + previousActiveTerminal.show(); + } + }, + ); + } return this.tempSessionDetails; }