Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/chat/browser/chatStatus/chatStatusItemService.ts
4780 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 { Emitter, Event } from '../../../../../base/common/event.js';
7
import { InstantiationType, registerSingleton } from '../../../../../platform/instantiation/common/extensions.js';
8
import { createDecorator } from '../../../../../platform/instantiation/common/instantiation.js';
9
10
export const IChatStatusItemService = createDecorator<IChatStatusItemService>('chatStatusItemService');
11
12
export interface IChatStatusItemService {
13
readonly _serviceBrand: undefined;
14
15
readonly onDidChange: Event<IChatStatusItemChangeEvent>;
16
17
setOrUpdateEntry(entry: ChatStatusEntry): void;
18
19
deleteEntry(id: string): void;
20
21
getEntries(): Iterable<ChatStatusEntry>;
22
}
23
24
export interface IChatStatusItemChangeEvent {
25
readonly entry: ChatStatusEntry;
26
}
27
28
export type ChatStatusEntry = {
29
id: string;
30
label: string | { label: string; link: string };
31
description: string;
32
detail: string | undefined;
33
};
34
35
class ChatStatusItemService implements IChatStatusItemService {
36
readonly _serviceBrand: undefined;
37
38
private readonly _entries = new Map<string, ChatStatusEntry>();
39
40
private readonly _onDidChange = new Emitter<IChatStatusItemChangeEvent>();
41
readonly onDidChange = this._onDidChange.event;
42
43
setOrUpdateEntry(entry: ChatStatusEntry): void {
44
const isUpdate = this._entries.has(entry.id);
45
this._entries.set(entry.id, entry);
46
if (isUpdate) {
47
this._onDidChange.fire({ entry });
48
}
49
}
50
51
deleteEntry(id: string): void {
52
this._entries.delete(id);
53
}
54
55
getEntries(): Iterable<ChatStatusEntry> {
56
return this._entries.values();
57
}
58
}
59
60
registerSingleton(IChatStatusItemService, ChatStatusItemService, InstantiationType.Delayed);
61
62