Skip to content

Commit 9248853

Browse files
authored
Add temporaryConsoleWindowActionOnDebugEnd option (#5255)
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.
1 parent afd1b69 commit 9248853

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

package.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,21 @@
581581
"type": "string",
582582
"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.",
583583
"default": false
584+
},
585+
"temporaryConsoleWindowActionOnDebugEnd": {
586+
"type": "string",
587+
"description": "Determines whether the temporary PowerShell Extension Terminal is closed when the debugging session ends.",
588+
"default": "keep",
589+
"enum": [
590+
"close",
591+
"hide",
592+
"keep"
593+
],
594+
"enumDescriptions": [
595+
"Closes the temporary PowerShell Extension Terminal when the debugging session ends.",
596+
"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.",
597+
"Keeps the temporary PowerShell Extension Terminal open after the debugging session ends."
598+
]
584599
}
585600
}
586601
},
@@ -615,6 +630,21 @@
615630
"type": "boolean",
616631
"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'.",
617632
"default": false
633+
},
634+
"temporaryConsoleWindowActionOnDebugEnd": {
635+
"type": "string",
636+
"description": "Determines whether the temporary PowerShell Extension Terminal is closed when the debugging session ends.",
637+
"default": "keep",
638+
"enum": [
639+
"close",
640+
"hide",
641+
"keep"
642+
],
643+
"enumDescriptions": [
644+
"Closes the temporary PowerShell Extension Terminal when the debugging session ends.",
645+
"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.",
646+
"Keeps the temporary PowerShell Extension Terminal open after the debugging session ends."
647+
]
618648
}
619649
}
620650
}

src/features/DebugSession.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,8 @@ export class DebugSessionFeature
466466
return this.resolveAttachDotnetDebugConfiguration(config);
467467
}
468468

469+
config.temporaryConsoleWindowActionOnDebugEnd ??= "keep";
470+
469471
return config;
470472
}
471473

@@ -498,6 +500,8 @@ export class DebugSessionFeature
498500
session: DebugSession,
499501
): Promise<IEditorServicesSessionDetails | undefined> {
500502
const settings = getSettings();
503+
const previousActiveTerminal = window.activeTerminal;
504+
501505
this.tempDebugProcess =
502506
await this.sessionManager.createDebugSessionProcess(
503507
settings,
@@ -600,6 +604,36 @@ export class DebugSessionFeature
600604
);
601605
}
602606

607+
if (
608+
session.configuration.temporaryConsoleWindowActionOnDebugEnd !==
609+
"keep"
610+
) {
611+
const closeDebugEvent = debug.onDidTerminateDebugSession(
612+
(terminatedSession) => {
613+
closeDebugEvent.dispose();
614+
615+
if (terminatedSession.id !== session.id) {
616+
return;
617+
}
618+
619+
if (
620+
terminatedSession.configuration
621+
.temporaryConsoleWindowActionOnDebugEnd === "close"
622+
) {
623+
this.tempDebugProcess?.dispose();
624+
} else if (
625+
terminatedSession.configuration
626+
.temporaryConsoleWindowActionOnDebugEnd ===
627+
"hide" &&
628+
previousActiveTerminal &&
629+
window.terminals.includes(previousActiveTerminal)
630+
) {
631+
previousActiveTerminal.show();
632+
}
633+
},
634+
);
635+
}
636+
603637
return this.tempSessionDetails;
604638
}
605639

@@ -705,6 +739,8 @@ export class DebugSessionFeature
705739
}
706740
}
707741

742+
config.temporaryConsoleWindowActionOnDebugEnd ??= "keep";
743+
708744
return config;
709745
}
710746

0 commit comments

Comments
 (0)