Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/api/common/extHostChatStatus.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 type * as vscode from 'vscode';
7
import * as extHostProtocol from './extHost.protocol.js';
8
import { ExtensionIdentifier, IExtensionDescription } from '../../../platform/extensions/common/extensions.js';
9
10
export class ExtHostChatStatus {
11
12
private readonly _proxy: extHostProtocol.MainThreadChatStatusShape;
13
14
private readonly _items = new Map<string, vscode.ChatStatusItem>();
15
16
constructor(
17
mainContext: extHostProtocol.IMainContext
18
) {
19
this._proxy = mainContext.getProxy(extHostProtocol.MainContext.MainThreadChatStatus);
20
}
21
22
createChatStatusItem(extension: IExtensionDescription, id: string): vscode.ChatStatusItem {
23
const internalId = asChatItemIdentifier(extension.identifier, id);
24
if (this._items.has(internalId)) {
25
throw new Error(`Chat status item '${id}' already exists`);
26
}
27
28
const state: extHostProtocol.ChatStatusItemDto = {
29
id: internalId,
30
title: '',
31
description: '',
32
detail: '',
33
};
34
35
let disposed = false;
36
let visible = false;
37
const syncState = () => {
38
if (disposed) {
39
throw new Error('Chat status item is disposed');
40
}
41
42
if (!visible) {
43
return;
44
}
45
46
this._proxy.$setEntry(id, state);
47
};
48
49
const item = Object.freeze<vscode.ChatStatusItem>({
50
id: id,
51
52
get title(): string | { label: string; link: string } {
53
return state.title;
54
},
55
set title(value: string | { label: string; link: string }) {
56
state.title = value;
57
syncState();
58
},
59
60
get description(): string {
61
return state.description;
62
},
63
set description(value: string) {
64
state.description = value;
65
syncState();
66
},
67
68
get detail(): string | undefined {
69
return state.detail;
70
},
71
set detail(value: string | undefined) {
72
state.detail = value;
73
syncState();
74
},
75
76
show: () => {
77
visible = true;
78
syncState();
79
},
80
hide: () => {
81
visible = false;
82
this._proxy.$disposeEntry(id);
83
},
84
dispose: () => {
85
disposed = true;
86
this._proxy.$disposeEntry(id);
87
this._items.delete(internalId);
88
},
89
});
90
91
this._items.set(internalId, item);
92
return item;
93
}
94
}
95
96
function asChatItemIdentifier(extension: ExtensionIdentifier, id: string): string {
97
return `${ExtensionIdentifier.toKey(extension)}.${id}`;
98
}
99
100
101