Path: blob/main/src/vs/workbench/contrib/debug/browser/debugStatus.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 * as nls from '../../../../nls.js';6import { IDisposable, dispose } from '../../../../base/common/lifecycle.js';7import { IDebugService, State, IDebugConfiguration } from '../common/debug.js';8import { IConfigurationService } from '../../../../platform/configuration/common/configuration.js';9import { IStatusbarEntry, IStatusbarService, StatusbarAlignment, IStatusbarEntryAccessor } from '../../../services/statusbar/browser/statusbar.js';10import { IWorkbenchContribution } from '../../../common/contributions.js';1112export class DebugStatusContribution implements IWorkbenchContribution {1314private showInStatusBar!: 'never' | 'always' | 'onFirstSessionStart';15private toDispose: IDisposable[] = [];16private entryAccessor: IStatusbarEntryAccessor | undefined;1718constructor(19@IStatusbarService private readonly statusBarService: IStatusbarService,20@IDebugService private readonly debugService: IDebugService,21@IConfigurationService configurationService: IConfigurationService22) {2324const addStatusBarEntry = () => {25this.entryAccessor = this.statusBarService.addEntry(this.entry, 'status.debug', StatusbarAlignment.LEFT, 30 /* Low Priority */);26};2728const setShowInStatusBar = () => {29this.showInStatusBar = configurationService.getValue<IDebugConfiguration>('debug').showInStatusBar;30if (this.showInStatusBar === 'always' && !this.entryAccessor) {31addStatusBarEntry();32}33};34setShowInStatusBar();3536this.toDispose.push(this.debugService.onDidChangeState(state => {37if (state !== State.Inactive && this.showInStatusBar === 'onFirstSessionStart' && !this.entryAccessor) {38addStatusBarEntry();39}40}));41this.toDispose.push(configurationService.onDidChangeConfiguration(e => {42if (e.affectsConfiguration('debug.showInStatusBar')) {43setShowInStatusBar();44if (this.entryAccessor && this.showInStatusBar === 'never') {45this.entryAccessor.dispose();46this.entryAccessor = undefined;47}48}49}));50this.toDispose.push(this.debugService.getConfigurationManager().onDidSelectConfiguration(e => {51this.entryAccessor?.update(this.entry);52}));53}5455private get entry(): IStatusbarEntry {56let text = '';57const manager = this.debugService.getConfigurationManager();58const name = manager.selectedConfiguration.name || '';59const nameAndLaunchPresent = name && manager.selectedConfiguration.launch;60if (nameAndLaunchPresent) {61text = (manager.getLaunches().length > 1 ? `${name} (${manager.selectedConfiguration.launch!.name})` : name);62}6364return {65name: nls.localize('status.debug', "Debug"),66text: '$(debug-alt-small) ' + text,67ariaLabel: nls.localize('debugTarget', "Debug: {0}", text),68tooltip: nls.localize('selectAndStartDebug', "Select and Start Debug Configuration"),69command: 'workbench.action.debug.selectandstart'70};71}7273dispose(): void {74this.entryAccessor?.dispose();75dispose(this.toDispose);76}77}787980