From 21d20148ee559305c68ed60fd3c6955bd27783ef Mon Sep 17 00:00:00 2001 From: Andre Weinand Date: Tue, 16 Mar 2021 13:09:26 +0100 Subject: [PATCH] new debug setting for clearing a terminal before reusing; fixes #116699 --- src/vs/workbench/api/node/extHostDebugService.ts | 16 +++++++++++++++- .../contrib/debug/browser/debug.contribution.ts | 5 +++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/vs/workbench/api/node/extHostDebugService.ts b/src/vs/workbench/api/node/extHostDebugService.ts index f2c8f2e18118b..c8c7f4cd50c1d 100644 --- a/src/vs/workbench/api/node/extHostDebugService.ts +++ b/src/vs/workbench/api/node/extHostDebugService.ts @@ -5,6 +5,7 @@ import * as nls from 'vs/nls'; import type * as vscode from 'vscode'; +import * as platform from 'vs/base/common/platform'; import { DebugAdapterExecutable } from 'vs/workbench/api/common/extHostTypes'; import { ExecutableDebugAdapter, SocketDebugAdapter, NamedPipeDebugAdapter } from 'vs/workbench/contrib/debug/node/debugAdapter'; import { AbstractDebugAdapter } from 'vs/workbench/contrib/debug/common/abstractDebugAdapter'; @@ -109,10 +110,23 @@ export class ExtHostDebugService extends ExtHostDebugServiceBase { if (giveShellTimeToInitialize) { // give a new terminal some time to initialize the shell await new Promise(resolve => setTimeout(resolve, 1000)); + } else { + if (configProvider.getConfiguration('debug.terminal').get('clearBeforeReusing')) { + // clear terminal before reusing it + if (shell.indexOf('powershell') >= 0 || shell.indexOf('pwsh') >= 0 || shell.indexOf('cmd.exe') >= 0) { + terminal.sendText('cls'); + } else if (shell.indexOf('bash') >= 0) { + terminal.sendText('clear'); + } else if (platform.isWindows) { + terminal.sendText('cls'); + } else { + terminal.sendText('clear'); + } + } } const command = prepareCommand(shell, args.args, cwdForPrepareCommand, args.env); - terminal.sendText(command, true); + terminal.sendText(command); // Mark terminal as unused when its session ends, see #112055 const sessionListener = this.onDidTerminateDebugSession(s => { diff --git a/src/vs/workbench/contrib/debug/browser/debug.contribution.ts b/src/vs/workbench/contrib/debug/browser/debug.contribution.ts index ce84ce7cf3491..c958b75dc30b3 100644 --- a/src/vs/workbench/contrib/debug/browser/debug.contribution.ts +++ b/src/vs/workbench/contrib/debug/browser/debug.contribution.ts @@ -398,6 +398,11 @@ configurationRegistry.registerConfiguration({ description: nls.localize('debug.console.closeOnEnd', "Controls if the debug console should be automatically closed when the debug session ends."), default: false }, + 'debug.terminal.clearBeforeReusing': { + type: 'boolean', + description: nls.localize({ comment: ['This is the description for a setting'], key: 'debug.terminal.clearBeforeReusing' }, "Before starting a new debug session in an integrated or external terminal, clear the terminal."), + default: false + }, 'debug.openDebug': { enum: ['neverOpen', 'openOnSessionStart', 'openOnFirstSessionStart', 'openOnDebugBreak'], default: 'openOnFirstSessionStart',