Path: blob/main/src/vs/workbench/contrib/chat/browser/chatStatusItemService.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 { Emitter, Event } from '../../../../base/common/event.js';6import { InstantiationType, registerSingleton } from '../../../../platform/instantiation/common/extensions.js';7import { createDecorator } from '../../../../platform/instantiation/common/instantiation.js';89export const IChatStatusItemService = createDecorator<IChatStatusItemService>('IChatStatusItemService');1011export interface IChatStatusItemService {12readonly _serviceBrand: undefined;1314readonly onDidChange: Event<IChatStatusItemChangeEvent>;1516setOrUpdateEntry(entry: ChatStatusEntry): void;1718deleteEntry(id: string): void;1920getEntries(): Iterable<ChatStatusEntry>;21}222324export interface IChatStatusItemChangeEvent {25readonly entry: ChatStatusEntry;26}2728export type ChatStatusEntry = {29id: string;30label: string | { label: string; link: string };31description: string;32detail: string | undefined;33};343536class ChatStatusItemService implements IChatStatusItemService {37readonly _serviceBrand: undefined;3839private readonly _entries = new Map<string, ChatStatusEntry>();4041private readonly _onDidChange = new Emitter<IChatStatusItemChangeEvent>();42readonly onDidChange = this._onDidChange.event;4344setOrUpdateEntry(entry: ChatStatusEntry): void {45const isUpdate = this._entries.has(entry.id);46this._entries.set(entry.id, entry);47if (isUpdate) {48this._onDidChange.fire({ entry });49}50}5152deleteEntry(id: string): void {53this._entries.delete(id);54}5556getEntries(): Iterable<ChatStatusEntry> {57return this._entries.values();58}59}6061registerSingleton(IChatStatusItemService, ChatStatusItemService, InstantiationType.Delayed);626364