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..49e964c44e 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,36 @@ export class DebugSessionFeature ); } + if ( + session.configuration.temporaryConsoleWindowActionOnDebugEnd !== + "keep" + ) { + 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" && + previousActiveTerminal && + window.terminals.includes(previousActiveTerminal) + ) { + previousActiveTerminal.show(); + } + }, + ); + } + return this.tempSessionDetails; } @@ -705,6 +739,8 @@ export class DebugSessionFeature } } + config.temporaryConsoleWindowActionOnDebugEnd ??= "keep"; + return config; }