Add debug.confirmOnExit - Fix #130664

This commit is contained in:
Rob Lourens 2021-08-18 22:04:14 -07:00
parent 81a3dceec5
commit 873db27553
3 changed files with 63 additions and 0 deletions

View file

@ -55,6 +55,7 @@ import { DisassemblyView, DisassemblyViewContribution } from 'vs/workbench/contr
import { EditorPaneDescriptor, IEditorPaneRegistry } from 'vs/workbench/browser/editor';
import { DisassemblyViewInput } from 'vs/workbench/contrib/debug/common/disassemblyViewInput';
import { Codicon } from 'vs/base/common/codicons';
import { DebugLifecycle } from 'vs/workbench/contrib/debug/common/debugLifecycle';
const debugCategory = nls.localize('debugCategory', "Debug");
registerColors();
@ -70,6 +71,7 @@ Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench).regi
Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench).registerWorkbenchContribution(DebugContentProvider, LifecyclePhase.Eventually);
Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench).registerWorkbenchContribution(StatusBarColorProvider, LifecyclePhase.Eventually);
Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench).registerWorkbenchContribution(DisassemblyViewContribution, LifecyclePhase.Eventually);
Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench).registerWorkbenchContribution(DebugLifecycle, LifecyclePhase.Eventually);
// Register Quick Access
Registry.as<IQuickAccessRegistry>(QuickAccessExtensions.Quickaccess).registerQuickAccessProvider({
@ -524,6 +526,16 @@ configurationRegistry.registerConfiguration({
],
default: 'allEditorsInActiveGroup',
scope: ConfigurationScope.LANGUAGE_OVERRIDABLE
},
'debug.confirmOnExit': {
description: nls.localize('debug.confirmOnExit', "Controls whether to confirm when the window closes if there are active debug sessions."),
type: 'string',
enum: ['never', 'always'],
enumDescriptions: [
nls.localize('debug.confirmOnExit.never', "Never confirm."),
nls.localize('debug.confirmOnExit.always', "Always confirm if there are debug sessions."),
],
default: 'never'
}
}
});

View file

@ -547,6 +547,7 @@ export interface IDebugConfiguration {
onTaskErrors: 'debugAnyway' | 'showErrors' | 'prompt' | 'abort';
showBreakpointsInOverviewRuler: boolean;
showInlineBreakpointCandidates: boolean;
confirmOnExit: 'always' | 'never';
}
export interface IGlobalConfig {

View file

@ -0,0 +1,50 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as nls from 'vs/nls';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IDialogService } from 'vs/platform/dialogs/common/dialogs';
import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
import { IDebugConfiguration, IDebugService } from 'vs/workbench/contrib/debug/common/debug';
import { ILifecycleService, ShutdownReason } from 'vs/workbench/services/lifecycle/common/lifecycle';
export class DebugLifecycle implements IWorkbenchContribution {
constructor(
@ILifecycleService lifecycleService: ILifecycleService,
@IDebugService private readonly debugService: IDebugService,
@IConfigurationService private readonly configurationService: IConfigurationService,
@IDialogService private readonly dialogService: IDialogService,
) {
lifecycleService.onBeforeShutdown(async e => e.veto(this.shouldVetoShutdown(e.reason), 'veto.debug'));
}
private shouldVetoShutdown(_reason: ShutdownReason): boolean | Promise<boolean> {
const rootSessions = this.debugService.getModel().getSessions().filter(s => s.parentSession === undefined);
if (rootSessions.length === 0) {
return false;
}
const shouldConfirmOnExit = this.configurationService.getValue<IDebugConfiguration>('debug').confirmOnExit;
if (shouldConfirmOnExit === 'never') {
return false;
}
return this._showWindowCloseConfirmation(rootSessions.length);
}
protected async _showWindowCloseConfirmation(numSessions: number): Promise<boolean> {
let message: string;
if (numSessions === 1) {
message = nls.localize('debug.debugSessionCloseConfirmationSingular', "There is an active debug session, are you sure you want to terminate it?");
} else {
message = nls.localize('debug.debugSessionCloseConfirmationPlural', "There are active debug sessions, are you sure you want to terminate them?");
}
const res = await this.dialogService.confirm({
message,
type: 'warning',
});
return !res.confirmed;
}
}