Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/chat/browser/chatStatusItemService.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 { 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>('IChatStatusItemService');
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
25
export interface IChatStatusItemChangeEvent {
26
readonly entry: ChatStatusEntry;
27
}
28
29
export type ChatStatusEntry = {
30
id: string;
31
label: string | { label: string; link: string };
32
description: string;
33
detail: string | undefined;
34
};
35
36
37
class ChatStatusItemService implements IChatStatusItemService {
38
readonly _serviceBrand: undefined;
39
40
private readonly _entries = new Map<string, ChatStatusEntry>();
41
42
private readonly _onDidChange = new Emitter<IChatStatusItemChangeEvent>();
43
readonly onDidChange = this._onDidChange.event;
44
45
setOrUpdateEntry(entry: ChatStatusEntry): void {
46
const isUpdate = this._entries.has(entry.id);
47
this._entries.set(entry.id, entry);
48
if (isUpdate) {
49
this._onDidChange.fire({ entry });
50
}
51
}
52
53
deleteEntry(id: string): void {
54
this._entries.delete(id);
55
}
56
57
getEntries(): Iterable<ChatStatusEntry> {
58
return this._entries.values();
59
}
60
}
61
62
registerSingleton(IChatStatusItemService, ChatStatusItemService, InstantiationType.Delayed);
63
64