Path: blob/main/src/vs/workbench/contrib/debug/common/debugLifecycle.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { IDisposable } from '../../../../base/common/lifecycle.js';6import * as nls from '../../../../nls.js';7import { IConfigurationService } from '../../../../platform/configuration/common/configuration.js';8import { IDialogService } from '../../../../platform/dialogs/common/dialogs.js';9import { IWorkbenchContribution } from '../../../common/contributions.js';10import { IDebugConfiguration, IDebugService } from './debug.js';11import { ILifecycleService, ShutdownReason } from '../../../services/lifecycle/common/lifecycle.js';1213export class DebugLifecycle implements IWorkbenchContribution {14private disposable: IDisposable;1516constructor(17@ILifecycleService lifecycleService: ILifecycleService,18@IDebugService private readonly debugService: IDebugService,19@IConfigurationService private readonly configurationService: IConfigurationService,20@IDialogService private readonly dialogService: IDialogService,21) {22this.disposable = lifecycleService.onBeforeShutdown(async e => e.veto(this.shouldVetoShutdown(e.reason), 'veto.debug'));23}2425private shouldVetoShutdown(_reason: ShutdownReason): boolean | Promise<boolean> {26const rootSessions = this.debugService.getModel().getSessions().filter(s => s.parentSession === undefined);27if (rootSessions.length === 0) {28return false;29}3031const shouldConfirmOnExit = this.configurationService.getValue<IDebugConfiguration>('debug').confirmOnExit;32if (shouldConfirmOnExit === 'never') {33return false;34}3536return this.showWindowCloseConfirmation(rootSessions.length);37}3839public dispose() {40return this.disposable.dispose();41}4243private async showWindowCloseConfirmation(numSessions: number): Promise<boolean> {44let message: string;45if (numSessions === 1) {46message = nls.localize('debug.debugSessionCloseConfirmationSingular', "There is an active debug session, are you sure you want to stop it?");47} else {48message = nls.localize('debug.debugSessionCloseConfirmationPlural', "There are active debug sessions, are you sure you want to stop them?");49}50const res = await this.dialogService.confirm({51message,52type: 'warning',53primaryButton: nls.localize({ key: 'debug.stop', comment: ['&& denotes a mnemonic'] }, "&&Stop Debugging")54});55return !res.confirmed;56}57}585960