Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/debug/browser/debugStatus.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 * as nls from '../../../../nls.js';
7
import { IDisposable, dispose } from '../../../../base/common/lifecycle.js';
8
import { IDebugService, State, IDebugConfiguration } from '../common/debug.js';
9
import { IConfigurationService } from '../../../../platform/configuration/common/configuration.js';
10
import { IStatusbarEntry, IStatusbarService, StatusbarAlignment, IStatusbarEntryAccessor } from '../../../services/statusbar/browser/statusbar.js';
11
import { IWorkbenchContribution } from '../../../common/contributions.js';
12
13
export class DebugStatusContribution implements IWorkbenchContribution {
14
15
private showInStatusBar!: 'never' | 'always' | 'onFirstSessionStart';
16
private toDispose: IDisposable[] = [];
17
private entryAccessor: IStatusbarEntryAccessor | undefined;
18
19
constructor(
20
@IStatusbarService private readonly statusBarService: IStatusbarService,
21
@IDebugService private readonly debugService: IDebugService,
22
@IConfigurationService configurationService: IConfigurationService
23
) {
24
25
const addStatusBarEntry = () => {
26
this.entryAccessor = this.statusBarService.addEntry(this.entry, 'status.debug', StatusbarAlignment.LEFT, 30 /* Low Priority */);
27
};
28
29
const setShowInStatusBar = () => {
30
this.showInStatusBar = configurationService.getValue<IDebugConfiguration>('debug').showInStatusBar;
31
if (this.showInStatusBar === 'always' && !this.entryAccessor) {
32
addStatusBarEntry();
33
}
34
};
35
setShowInStatusBar();
36
37
this.toDispose.push(this.debugService.onDidChangeState(state => {
38
if (state !== State.Inactive && this.showInStatusBar === 'onFirstSessionStart' && !this.entryAccessor) {
39
addStatusBarEntry();
40
}
41
}));
42
this.toDispose.push(configurationService.onDidChangeConfiguration(e => {
43
if (e.affectsConfiguration('debug.showInStatusBar')) {
44
setShowInStatusBar();
45
if (this.entryAccessor && this.showInStatusBar === 'never') {
46
this.entryAccessor.dispose();
47
this.entryAccessor = undefined;
48
}
49
}
50
}));
51
this.toDispose.push(this.debugService.getConfigurationManager().onDidSelectConfiguration(e => {
52
this.entryAccessor?.update(this.entry);
53
}));
54
}
55
56
private get entry(): IStatusbarEntry {
57
let text = '';
58
const manager = this.debugService.getConfigurationManager();
59
const name = manager.selectedConfiguration.name || '';
60
const nameAndLaunchPresent = name && manager.selectedConfiguration.launch;
61
if (nameAndLaunchPresent) {
62
text = (manager.getLaunches().length > 1 ? `${name} (${manager.selectedConfiguration.launch!.name})` : name);
63
}
64
65
return {
66
name: nls.localize('status.debug', "Debug"),
67
text: '$(debug-alt-small) ' + text,
68
ariaLabel: nls.localize('debugTarget', "Debug: {0}", text),
69
tooltip: nls.localize('selectAndStartDebug', "Select and Start Debug Configuration"),
70
command: 'workbench.action.debug.selectandstart'
71
};
72
}
73
74
dispose(): void {
75
this.entryAccessor?.dispose();
76
dispose(this.toDispose);
77
}
78
}
79
80