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