Path: blob/main/src/vs/workbench/contrib/chat/browser/chatStatus/chatStatusItemService.ts
4780 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>('chatStatusItemService');1011export interface IChatStatusItemService {12readonly _serviceBrand: undefined;1314readonly onDidChange: Event<IChatStatusItemChangeEvent>;1516setOrUpdateEntry(entry: ChatStatusEntry): void;1718deleteEntry(id: string): void;1920getEntries(): Iterable<ChatStatusEntry>;21}2223export interface IChatStatusItemChangeEvent {24readonly entry: ChatStatusEntry;25}2627export type ChatStatusEntry = {28id: string;29label: string | { label: string; link: string };30description: string;31detail: string | undefined;32};3334class ChatStatusItemService implements IChatStatusItemService {35readonly _serviceBrand: undefined;3637private readonly _entries = new Map<string, ChatStatusEntry>();3839private readonly _onDidChange = new Emitter<IChatStatusItemChangeEvent>();40readonly onDidChange = this._onDidChange.event;4142setOrUpdateEntry(entry: ChatStatusEntry): void {43const isUpdate = this._entries.has(entry.id);44this._entries.set(entry.id, entry);45if (isUpdate) {46this._onDidChange.fire({ entry });47}48}4950deleteEntry(id: string): void {51this._entries.delete(id);52}5354getEntries(): Iterable<ChatStatusEntry> {55return this._entries.values();56}57}5859registerSingleton(IChatStatusItemService, ChatStatusItemService, InstantiationType.Delayed);606162